Fail2ban 暴力破解防护
fail2ban 监控日志中的失败登录,按规则临时封禁来源 IP。它通过 jail 配置过滤器、动作和阈值,常与 iptables/nftables/firewalld 配合。
fail2ban-client status
fail2ban-client status sshd
fail2ban-client set sshd banip 203.0.113.10
fail2ban-client set sshd unbanip 203.0.113.10
fail2ban-client reload
fail2ban-client -t
fail2ban-regex /var/log/auth.log /etc/fail2ban/filter.d/sshd.conf
jail.local:
[DEFAULT]
bantime = 1h
findtime = 10m
maxretry = 5
ignoreip = 127.0.0.1/8 10.0.0.0/8
[sshd]
enabled = true
port = ssh
logpath = %(sshd_log)s
backend = systemd
status 的失败计数。ignoreip 必须包含管理网段和跳板机,避免把自己锁在外面。findtime/maxretry 太严会误封 NAT 后的正常用户。fail2ban-client — 管理fail2ban-regex — 测试过滤器iptables / nft — 封禁动作