共计 794 个字符,预计需要花费 2 分钟才能阅读完成。
安装 fail2ban
yum install fail2ban -y
启用 fail2ban
service fail2ban start
设置开机启动
chkconfig fail2ban on
修改配置文件
在 /etc/fail2ban/ 下有个 jail.conf
编辑文件
vim /etc/fail2ban/jail.conf
在后面添加下面的内容
[Default]
[ssh-iptables]
ignoreip = 127.0.0.1
backend=auto
enabled=true
filter= sshd
action= iptables[name=SSH, port=ssh, protocol=tcp]
logpath=/var/log/secure
bantime=600
findtime=300
maxretry=3
重启服务
service fail2ban restart
查看 fail2ban 状态
fail2ban-client status
需要查看 ssh 封禁情况可以运行:
fail2ban-client status ssh
相比于更改端口或是禁止 root 帐号,Fail2ban 会使用极少量的系统资源,不过对于普通的 VPS 而言可以说是微不足道了。