更改 fail2ban 设置以使用 pf 进行阻止
大家好,我是无能。今天是一篇无能中的无能文章。
咦!?fail2ban.log 里好像有奇怪的日志!
好吧好吧,正想着看看 fail2ban 阻止了什么……结果发现
2024-07-24 20:52:43,027 fail2ban.utils [39963]: INFO HINT on 127: "Command not found". Make sure that all commands
in "{ iptables -w -C f2b-sshd -j RETURN >/dev/null 2>&1; } || { iptables -w -N f2b-sshd || true; iptables -w -A f2b-sshd -j RE
TURN; }
for proto in $(echo 'tcp' | sed 's/,/ /g'); do
{ iptables -w -C INPUT -p $proto -m multiport --dports ssh -j f2b-sshd
>/dev/null 2>&1; } || { iptables -w -I INPUT -p $proto -m multiport --dports ssh -j f2b-sshd; }
done" are in the PATH of fail
2ban-server process (grep -a PATH= /proc/pidof -x fail2ban-server/environ). You may want to start "fail2ban-server -f" separa
tely, initiate it with "fail2ban-client reload" in another shell session and observe if additional informative error messages a
ppear in the terminals.
咦,显示说找不到命令……我完全忘了!!!
FreeBSD 的情况是用 pf 控制的……GNU/Linux 的情况用 iptables 就可以了,但我明明在用 BSD 却完全忘了……所以,我将参考这个网站重新设置……https://dbdemon.com/pf_and_fail2ban因此,我将我的自建服务器设为 $exsrv1,所以
# Fail2Ban
table <f2b> persist
anchor "f2b/*"
block drop in log quick on $exsrv1 from <f2b> to any
这样就设置好了。话说,f2b/* 竟然可以作为正则表达式吗……然后,重新设置 jail.conf。我乖乖地放到了 Default 部分。
[DEFAULT]
banaction = pf[actiontype=<allports>]
banaction_allports = pf[actiontype=<allports>]
[sshd]
enabled = true
port = ssh
logpath = /var/log/auth.log
bantime = 1w
findtime = 1d
maxretry = 5
[postfix]
enabled = true
port = smtp,ssmtp,submission
logpath = /var/log/maillog
bantime = 1w
findtime = 1d
maxretry = 10
[dovecot]
enabled = true
port = pop3,pop3s,imap,imaps,submission
logpath = /var/log/maillog
bantime = 1w
findtime = 1d
maxretry = 10
从配置文件来看,action.d/pf.conf 中默认已经设置好了,查看后发现
看起来像这样,调用命令时似乎不需要特别修改。然后,重启 fail2ban 和 pf,查看 fail2ban 的日志,发现之前被阻止的 IP 似乎都继承了下来。
# fail2ban-client status sshd
Status for the jail: sshd
|- Filter
| |- Currently failed: 1
| |- Total failed: 1
| `- File list: /var/log/auth.log
`- Actions
|- Currently banned: 37
|- Total banned: 37
`- Banned IP list: *
接下来我会再观察一下。
那么。下次再见。