原文:http://www.weiruoyu.cn/?p=474
方法一:
1.vi /etc/sysconfig/iptables里:RH-Firewall-1-INPUT - [0:0]下面添加一行
下面是只允许某个IP访问xx端口
-A INPUT -s 192.168.5.244 -j DROP
2.重启生效
#service iptables restart
方法二:
1.先备份iptables
# cp /etc/sysconfig/iptables /var/tmp
2.添加拒绝IP
更详细的请参考:http://www.weiruoyu.cn/?p=474
----------------下面是参考------------------------------------
1. 查看本机关于IPTABLES的设置情况
# iptables -L -n2. 清除原有规则
# 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 ACCEPT6. 禁止某个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 ACCEPTPing 洪水攻击(Ping of Death)
# iptables -A FORWARD -p icmp –icmp-type echo-request -m limit –limit 1/s -j ACCEPT