使用Fail2Ban动态封禁IP

Fail2Ban 可以动态封禁多次尝试登录失败的 IP。

步骤:

  1. 安装 Fail2Ban
1
sudo apt install fail2ban
  1. 配置 Fail2Ban
    编辑配置文件 /etc/fail2ban/jail.local
1
sudo vim /etc/fail2ban/jail.local

添加以下内容:

1
2
3
4
[sshd]
enabled = true
maxretry = 3
bantime = 3600
  1. 重启 Fail2Ban
    重启 Fail2Ban 以应用配置:
sudo systemctl restart fail2ban
  1. 验证配置
    查看封禁的 IP:
sudo fail2ban-client status sshd

使用Fail2Ban动态封禁IP
http://blog.iworkce.com/2025/02/21/fail2ban/
作者
Lan Lin
发布于
2025年2月21日
许可协议