安裝:fail2banpython
[root@xuegod63 ~]# tar -zxvf fail2ban-0.8.14.tar.gzvim
[root@xuegod63 fail2ban-0.8.14]# cdfail2ban-0.8.14ssh
查看安裝指南README.mdtcp
[root@xuegod63 ~]# cdfail2ban-0.8.14ide
[root@xuegod63fail2ban-0.8.14]#python setup.py install測試
生成服務啓動腳本:spa
[root@xuegod63fail2ban-0.8.14]# cp files/redhat-initd /etc/init.d/fail2banip
[root@xuegod63fail2ban-0.8.14]# chkconfig --add fail2banit
[root@xuegod63fail2ban-0.8.14]# chkconfig --listfail2banio
fail2ban 0:off 1:off 2:off 3:on 4:on 5:on 6:off
設置條件:ssh遠程登陸5分鐘內3次密碼驗證失敗,禁止用戶IP訪問主機1小時,1小時該限制自動解除,此IP能夠從新登陸。
[root@xuegod63 ~]# vim /etc/fail2ban/jail.conf #改如下紅色標記內容
[ssh-iptables]
enabled =true
filter = sshd
action = iptables[name=SSH, port=ssh,protocol=tcp]
sendmail-whois[name=SSH,dest=you@example.com, sender=fail2ban@example.com,sendername="Fail2Ban"]
logpath = /var/log/secure
findtime = 300 #須要新添加
maxretry = 3
bantime = 3600 #須要新添加
啓動服務:
[root@xuegod63 fail2ban-0.8.14]#servicefail2ban start
Starting fail2ban: [肯定]
測試
查看fail2ban服務運行狀態:
[root@xuegod63fail2ban]# fail2ban-clientstatus #配置好以後咱們檢測下fail2ban是否工做。
Status
|-Number of jail: 1
`-Jail list: ssh-iptables
[root@xuegod63fail2ban]# fail2ban-client status ssh-iptables
#具體看某一項的狀態也能夠看,若是顯示被ban的ip和數目就表示成功了,若是都是0,說明沒有成功。
Statusfor the jail: ssh-iptables
|-filter
| |- File list: /var/log/secure
| |- Currently failed: 0
| `- Total failed: 3
`-action
|- Currently banned: 1
| `-IP list: 192.168.1.2
`- Total banned: 1