CentOS 7 fail2ban 防暴力破解
使用 yum 安装 fail2ban
先安装 epel
yum -y install epel-release
Bash
安装 fail2ban
yum -y install fail2ban
Bash
启动服务
systemctl enable fail2ban
systemctl start fail2ban
Bash
查看版本
fail2ban-client -V
Fail2Ban v0.9.7
Copyright © 2004-2008 Cyril Jaquier, 2008- Fail2Ban Contributors
Copyright of modifications held by their respective authors.
Licensed under the GNU General Public License v2 (GPL).
Written by Cyril Jaquier cyril.jaquier@fail2ban.org.
Many contributions by Yaroslav O. Halchenko
Bash
修改配置文件
vim /etc/fail2ban/jail.conf
Bash
在末尾添加
[ssh-iptables]
enabled = true
filter = sshd
action = iptables[name=SSH, port=ssh, protocol=tcp]
#sendmail-whois[name=SSH,dest=your@email.com,sender=fail2ban@email.com]
logpath = /var/log/secure
maxretry = 3
bantime = 300
Bash
重启服务
systemctl restart fail2ban
Bash
在其他服务器
ssh root@172.16.231.144
Bash
故意输入三次错误密码后提示
ssh: connect to host 172.16.231.144 : Connection refused
Bash
在 fail2ban 服务器中查看
fail2ban-client status ssh-iptables
Bash
显示如下,发现已经添加了规则,
Status for the jail: ssh-iptables
|- Filter
| |- Currently failed: 0
| |- Total failed: 6
| - File list: /var/log/secure
- Actions
|- Currently banned: 1
|- Total banned: 2
`- Banned IP list: 172.16.231.144