iptables –F 

#删除已经存在的规则 

iptables -P INPUT DROP 

#配置默认的拒绝规则。基本规则是:先拒绝所有的服务,然后根据需要再添加新的规则。 

iptables -A INPUT -p tcp --dport 80 -j ACCEPT 

#打开WEB服务端口的tcp协议 

iptables -A INPUT -p tcp --dport 110 -j ACCEPT 

#打开POP3服务端口的tcp协议 

iptables -A INPUT -p tcp --dport 25 -j ACCEPT 

#打开SMTP服务端口的tcp协议 

iptables -A INPUT -p tcp --dport 21 -j ACCEPT 

#打开FTP服务端口的tcp协议 

iptables -A INPUT -p tcp -s 202.106.12.130 --dport 22 -j ACCEPT 

#允许IP地址为202.106.12.130这台主机连接本地的SSH服务端口 

iptables -A INPUT -p tcp --dport 53 -j ACCEPT 

#允许DNS服务端口的tcp数据包流入 

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

#允许DNS服务端口的udp数据包流入 

iptables -A INPUT -p icmp -icmp-type echo-request -i eth1 -j DROP 

#防止死亡之ping,从接口eth1进入的icmp协议的请求全部丢弃。 

iptables -A FORWARD -p tcp --syn -m limit --limit 1/s -j ACCEPT 

#防止SYN Flood (拒绝服务攻击)


iptables -t nat -A POSTROUTING -o eth1 -s 192.168.0.226 -j MASQUERADE

#允许 192.168.0.226通过eth1 IP伪装出外网

iptables -t nat -A POSTROUTING -o eth0 -s 192.168.0.4 -p tcp --dport 25 -j MASQUERADE

#允许 192.168.0.4通过eth0 伪装访问外网的 25端口