安裝(須要安裝python) :python
tar xf fail2ban-0.8.14.tar.gz ssh
cd fail2ban-0.8.14tcp
./setup.py installide
cp files/redhat-initd /etc/init.d/fail2ban模塊化
chkconfig --add fail2banspa
服務配置目錄爲:/etc/fail2ban3d
/etc/fail2ban/action.d #動做文件夾,內含默認文件。iptables以及mail等動做配置日誌
/etc/fail2ban/fail2ban.conf #定義了fail2ban日誌級別、日誌位置及sock文件位置blog
/etc/fail2ban/filter.d #條件文件夾,內含默認文件。過濾日誌關鍵內容設置圖片
/etc/fail2ban/jail.conf #主要配置文件,模塊化。主要設置啓用ban動做的服務及動做閥值
/etc/rc.d/init.d/fail2ban #啓動腳本文件
安裝後配置:
cat /etc/fail2ban/fail2ban.conf |grep -v ^#
cat /etc/fail2ban/jail.conf |grep -v ^#|more
[DEFAULT] #全局設置
ignoreip = 127.0.0.1/8 #忽略的IP列表,不受設置限制(白名單)
ignoreip = 192.168.200.157
bantime = 600 #屏蔽時間,單位:秒
findtime = 600 #這個時間段內超過規定次數會被ban掉
maxretry = 3 #最大嘗試次數
backend = auto #日誌修改檢測機制(gamin、polling和auto這三種)
[ssh-iptables] #針對各服務的檢查配置,如設置bantime、findtime、maxretry和全局衝突,服務優先級大於全局設置
enabled = true #是否激活此項(true/false)
filter = sshd #過濾規則filter的名字,對應filter.d目錄下的sshd.conf
action = iptables[name=SSH, port=ssh, protocol=tcp] #動做的相關參數
sendmail-whois[name=SSH,dest=***@***.com,sender=root,sendername="Fail2Ban"] #觸發報警的收件人
logpath = /var/log/secure #檢測的系統的登錄日誌文件
maxretry = 5 #最大嘗試次數
啓動:
service fail2ban start #啓動服務便可(就用默認的主配置文件裏定義的)
service iptables start #fail2ban依賴預iptables
查看狀態:
fail2ban-client status
查看被阻止的ip:
iptables -L