使用 iptables 限制黑客猜密码续—深入 recent 模块 http://www.cnblogs.com/hiloves/archive/2011/07/19/2109899.html 这里提到为什么不能使用, 可能是因为命令的顺序不对(包括所有规则的顺序)
SSH时间锁定技巧 http://blog.sina.com.cn/s/blog_976e49570100zb23.html
防止ssh密码扫描 http://xstarcd.github.io/wiki/Linux/ssh_security_blanklist.html 测试成功
Iptables模块recent应用 http://www.haiyun.me/archives/iptables-recent.html
注意: 规则的顺序, 很重要
默认
1 2 3 4 5 6 7 8 9 10 11 |
*filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT -A INPUT -j REJECT --reject-with icmp-host-prohibited -A FORWARD -j REJECT --reject-with icmp-host-prohibited COMMIT |
测试成功: 修改后可以使用, INPUT默认是DROP或者ACCEPT都可以使用, name是规则记录的列表名称
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
*filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [458:123843] -A INPUT -i lo -j ACCEPT -A INPUT -i tap+ -j ACCEPT -A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT #防止端口扫描规则前面部分, 如果某个IP地址对非Linux主机允许的端口发起连接,并且一分钟内超过3次,则系统将中断该主机与本机的连接 -A INPUT -m recent --update --seconds 60 --hitcount 3 --name PORTSCAN --rsource -j DROP -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT # 防止穷举主机口令, 如果某IP地址在一分钟之内对Linux主机22/TCP端口新发起的连接超过2次,之后的新发起的连接将被丢弃。 -A INPUT -p tcp -m tcp --dport 22 -m state --state NEW -m recent --update --seconds 60 --hitcount 2 --name SSH --rsource -j DROP -A INPUT -p tcp -m tcp --dport 22 -m state --state NEW -m recent --set --name SSH --rsource -j ACCEPT #防止端口扫描规则后部分 -A INPUT -m recent --set --name PORTSCAN --rsource -j DROP -A INPUT -j REJECT --reject-with icmp-host-prohibited -A FORWARD -j REJECT --reject-with icmp-host-prohibited COMMIT |
规则处理:
ACCETP : 通过
DROP : 丢弃
REJECT : 拒绝
操作命令:
1 2 3 4 |
vim /etc/sysconfig/iptables /etc/init.d/iptables save /etc/init.d/iptables status service iptables restart |