centeros iptable模板文件
vi /etc/sysconfig/iptables
# Generated by iptables-save v1.4.7 on Mon Mar 26 09:52:21 2012
*filter
:INPUT ACCEPT [0:0]
:FORWARD DROP [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
# Completed
:wq
service iptables start
/etc/sysconfig/iptables 模板
*filter
:INPUT ACCEPT [0:0]
:FORWARD DROP [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 -m state --state NEW -m tcp -p tcp --dport 10622 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
/etc/fail2ban/jail.conf中增加以下配置:
[ssh-iptables]
enabled = true
filter = sshd
action = iptables[name=SSH, port=ssh, protocol=tcp]
#action = iptables[name=SSH, port=10622, protocol=tcp]
sendmail-whois[name=SSH, dest=hujha@chanjet.com, sender=fail2ban@email.com]
# Debian 系的发行版
#logpath =/var/log/auth.log
# Red Hat 系的发行版
logpath =/var/log/secure
# ssh 服务的最大尝试次数
maxretry =3
findtime =60
bantime =600
测试:
fail2ban-client status ssh-iptables
fail2ban-client ping