RedHat 7.2- CentOS 7.2安装Fail2Ban

好久没更新了,进来帮朋友装了vps。我这种懒人基本就是lnmpa一件安装包了。军哥的确做了件好事,自己编译要好多时间。装好后第二天发现如此盛况:

Failed password for root
Failed password for root

一天,就这么多字典攻击。我没禁用root用户登录,也没有禁用密码登录,结果就是这样了。因为对方需要root并切只能用root以及密码登录,我就想起了领导以前交代的fail2ban和denyhosts.这里使用fail2ban,因为这货不但功能强大而且超级稳定。并且短时间内不会收到升级的影响。简单记录下步骤:
1. 下载

wget https://github.com/fail2ban/fail2ban/archive/0.8.14.tar.gz

2. 安装

tar xvzf ./0.8.14.tar.gz --解压缩
python ./setup.py install

3. 自动启动

cp ./files/redhat-initd /etc/init.d/fail2ban
chkconfig --add fail2ban
chkconfig --list
fail2ban 0:off 1:off 2:off 3:on 4:on 5:on 6:off
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off
sudo /etc/init.d/fail2ban start

5. 配置

sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local

编辑jail.local 找到 [ssh-iptables]部分编辑(RedHat7.2和CentOS 7.2如下所示)

a. logpath = /var/log/secure 检测日志位置
b. findtime = 300 检测周期
c. maxretry = 3 三次错误就ban
d. bantime = 3600 ban一小时

6. 测试

sudo fail2ban-client ping
Server replied: pong

sudo fail2ban-client status
Status
|- Number of jail: 1
`- Jail list: ssh-iptables

7. 大功告成!

Scroll to Top