1. 查看本机关于IPTABLES的设置情况
# iptables -L -n
2. 清除原有规则
# iptables -F 清除预设表filter中的所有规则链的规则
# iptables -X 清除预设表filter中使用者自定链中的规则
3. 保存设置规则(因配置随系统重启而失效)
# /etc/rc.d/init.d/iptables save
保存规则到/etc/sysconfig/iptables文件中, 也可手工编辑该文件.
4. 设定预设规则
# iptables -p INPUT DROP
# iptables -p OUTPUT DROP
# iptables -p FORWARD DROP
上面的规则是不允许任何包通过.
5. 添加规则
# iptables -A INPUT -p tcp –dport 22 -j ACCEPT
# iptables -A OUTPUT -p tcp –sport 22 -j ACCEPT
开启22端口, 允许SSH登录, 如开启80端口:
# iptables -A INPUT -p tcp –dport 80 -j ACCEPT
# iptables -A OUTPUT -p tcp –sport 80 -j ACCEPT
6. 禁止某个IP访问
# iptables -I INPUT -s x.x.x.x -j DROP
也可进行更细致的设置, 如只允许192.168.1.14的机器进行SSH连接:
# iptables -A INPUT -p tcp –dport 22 -s 192.168.1.14 -j ACCEPT
如果要允许或限制一段IP地址可用192.168.1.0/24 表示192.168.1.1-255端的所有IP.
防止同步包洪水(Sync Flood)
# iptables -A FORWARD -p tcp –syn -m limit –limit 1/s -j ACCEPT
防止各种端口扫描
# iptables -A FORWARD -p tcp –tcp-flags SYN,ACK,FIN,RST RST -m limit –limit 1/s -j ACCEPT
Ping 洪水***(Ping of Death)
# iptables -A FORWARD -p icmp –icmp-type echo-request -m limit –limit 1/s -j ACCEPT