安装 fail2ban
以 ubuntu 系统为例:
sudo apt update |
创建自定义配置文件
不要直接修改默认的 /etc/fail2ban/jail.conf,请复制一份作为本地自定义配置:
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local |
修改配置文件
编辑 /etc/fail2ban/jail.local 文件:
针对 SSH 服务的典型配置样例(1 分钟错误 10 次,封禁 1 小时):
[sshd] |
启动服务并设置开机启动
sudo systemctl start fail2ban |
服务重启命令(修改配置后需要执行):
sudo systemctl restart fail2ban |
常用管理命令
查看 SSH 封禁状态: sudo fail2ban-client status sshd
手动解封 IP: sudo fail2ban-client set sshd unbanip <IP_ADDRESS>
Fin.
扫描二维码,分享此文章