1.yum -y install fail2ban
2.vim /etc/fail2ban/fail2ban.conf
這個設定檔需要調整的部份不多,請修改 logtarget 的參數如下:
#預設的參數
#logtarget = SYSLOG
#調整後的參數
logtarget = /var/log/fail2ban.log
3.vim /etc/fail2ban/jail.conf
#預設的參數
#backend = auto
#調整後的參數
backend = gamin
[ssh-iptables]
#是否啟用
enabled = true
#過濾名稱,使用預設的即可
filter = sshd
#iptables設定
action = iptables[name=SSH, port=ssh, protocol=tcp]
#發生阻擋時的寄信設定
sendmail-whois[name=SSH, dest=pulipuli.chen@gmail.com, sender=root@server.nccu.edu.tw]
#需要掃描的記錄檔
logpath = /var/log/secure
#最高嘗試錯誤次數
maxretry = 2
#阻擋的時間,-1表示永久阻擋
bantime = -1
4.設定fail2ban開機順序
chkconfig --add fail2ban
設定好之後重開機
reboot
用iptables的語法來刪除被阻擋的IP:
[root@server ~]# iptables -D fail2ban-SSH –s 140.119.1.110 -j REJECT
參考來源
http://www.fail2ban.org/wiki/index.php/Main_Page
http://pulipuli.blogspot.tw/2011/07/centosfail2ban.html#postcata1399533997683_anchor0
Thanks for sharing valuable information. Your blogs were helpful to AWS learners. I
回覆刪除request to update the blog through step-by-step. Also, find the AWS news at
AWS Online Training