近日发现很多对于端口的扫描,虽然由于 ufw 的拦截并不能进入,但还是想用 fail2ban 来封禁这些 IP,减少被扫描的次数。因此增加了更多的 jail 配置。

jail

编辑 /etc/fail2ban/jail.d/defaults-debian.conf 文件,定义从哪里读取,以及对应操作:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
[DEFAULT]
banaction = ufw
bantime = 10m
banTime.increment = true

[sshd]
enabled = true

[ufw]
enabled = true
filte = ufw
action = iptables-allports
logpath = /var/log/ufw.log
maxretry = 1

filter

编辑 /etc/fail2ban/filter.d/ufw.conf 文件,定义正则表达式模板:

1
2
3
[Definition]
failregex = [UFW BLOCK].+SRC=<HOST> DST
ignoreregex =

action

/etc/fail2ban/action.d/ufw.conf 这个文件是现成的不需要改动,直接拿来用。