[网络配置] iptables 部分规则没有生效

weixin_38049770 2013-03-12 05:55:57

目前尝试着使用linux做服务器,到目前为止,接触一个月不到,总有一些问题。望大家帮帮忙。

目前情况:
目前是用的vps,有两个ip,vps只做web服务器,提供web服务,以及ftp服务,需要能连接到外网,能ping外网,能使用外部smtp发送邮件,能连外部ftp

因为两个ip,所以我希望一个ip提供web服务,其它的使用另一个ip,感觉这样安全点。

192.168.8.8 提供web服务
192.168.8.9 提供其它功能

以上两个ip为示例哦。

配置如下:#!/bin/bash

#清除所有规则
iptables -F
iptables -X
iptables -Z

#设置默认规则
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP

#允许本地的io(其实根本不懂这一行是什么意思)
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT

#这两行也不懂,但是每个例子都有加。。。
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

#http service 如果访问192.168.8.8这个ip,且端口为80,则允许,出口为80的不限
iptables -A INPUT -d 192.168.8.8 -p tcp --dport 80 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 80 -j ACCEPT

#ssh service 如果访问 192.168.8.9,且端口为234(端口自己改过的)则允许,访问192.168.8.8不允许连接ssh服务
iptables -A INPUT -d 192.168.8.9 -p tcp --dport 234 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 234 -j ACCEPT

#ftp 外部连接192.168.8.9ftp服务则允许,连接其它ip则不允许
iptables -A INPUT -d 192.168.8.9 -p tcp --dport 21 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 21 -j ACCEPT

#smtp 允许连接外部smtp服务
iptables -A OUTPUT -p tcp --dport 25 -j ACCEPT

iptables -A OUTPUT -p udp --dport 53 -j ACCEPT

#ping 允许外部ping192.168.8.9这个ip,允许内部ping外部
iptables -A INPUT -d 192.168.8.9 -p icmp -m icmp --icmp-type 8 -j ACCEPT
iptables -A INPUT -d 192.168.8.9 -p icmp -m icmp --icmp-type 11 -j ACCEPT
iptables -A OUTPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
iptables -A OUTPUT -p icmp -m icmp --icmp-type 11 -j ACCEPT
#不知道这条要不要
iptables -A INPUT -p tcp --syn -m limit --limit 1/s -j ACCEPT复制代码以上是规则,现在的问题是,我不知道,为什么ftp和ssh,使用192.168.8.8,192.168.8.9都能访问,我明明限制了只能192.168.8.9访问啊。至于ping已经成功了。。是什么导致ftp和ssh不成功呢?》??

望知道的前辈指导一二。。。
...全文
90 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复

476

社区成员

发帖
与我相关
我的任务
社区描述
其他技术讨论专区
其他 技术论坛(原bbs)
社区管理员
  • 其他技术讨论专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧