有些开放外网端口的主机,疯狂的遭遇密码尝试入侵,虽然密码设置的较为复杂,但是长时间的密码尝试会给/var/logs/secure写入大量日志,从而也会增加系统负担。fail2ban就可以很好的解决这个问题,设置最大尝试的次数,当超过指定次数时,fail2ban会调用iptables把尝试探测的IP加入到黑名单,并且锁定一断时间,次数和锁定时间可以根据自己设置,需要启动iptables,以下是一键配置脚本:
#!/bin/bash #author by thundermeng #mail:[email protected] #Install fail2ban wget http://soft.kwx.gd/security/fail2ban-0.8.4.tar.bz2 tar xfj fail2ban-0.8.4.tar.bz2 cd fail2ban-0.8.4 python setup.py install cd files cp ./redhat-initd /etc/init.d/fail2ban chkconfig fail2ban on #Configuration sed -i ‘/\[ssh-iptables\]/{n;n;s/enabled = false/enabled = true/}‘ /etc/fail2ban/jail.conf sed -ri ‘/^\[ssh-iptables\]$/,/^\[ssh-ddos\]$/{s#(logpath =).*#\1 /var/log/secure#}‘ /etc/fail2ban/jail.conf /etc/init.d/iptables start /etc/init.d/fail2ban start fail2ban-client status iptables -L
时间: 2024-10-25 00:12:58