使用 Ubuntu 20.04 LTS,我在 /etc/fail2ban/jail.local 中有这个:
[DEFAULT]
bantime = 3600
banaction = iptables
blocktype = drop
[sshd]
enabled = true
protocol = tcp
port = ssh
filter = sshd
logpath = /var/log/auth.log
maxretry = 3
但这是我在列出 iptables 规则时看到的:
╰─# iptables -L f2b-sshd -n -v
Chain f2b-sshd (1 references)
pkts bytes target prot opt in out source destination
13 1356 REJECT all -- * * 222.187.232.205 0.0.0.0/0 reject-with icmp-port-unreachable
18 1516 REJECT all -- * * 221.181.185.153 0.0.0.0/0 reject-with icmp-port-unreachable
17 1064 REJECT all -- * * 222.186.180.130 0.0.0.0/0 777 55854 RETURN all -- * * 0.0.0.0/0 0.0.0.0/0
问题是它使用 REJECT(使用 ICMP)而不是 DROP。
action.d/iptables.conf 包含以下内容:
# Option: actionban
# Notes.: command executed when banning an IP. Take care that the
# command is executed with Fail2Ban user rights.
# Tags: See jail.conf(5) man page
# Values: CMD
#
actionban = <iptables> -I f2b-<name> 1 -s <ip> -j <blocktype>
它是默认的 iptables 操作文件,随该操作系统版本的官方 fail2ban apt 软件包一起提供。
还尝试在 [sshd] 下添加“blocktype=drop”,但没有效果。
我不确定如何调试它,因为 fail2ban 服务不会记录实际的 iptables 命令。
我错过了什么?