fail2ban 日志中满是“无法执行 ban jail 'recidive' 操作 'iptables-multiport'”

fail2ban 日志中满是“无法执行 ban jail 'recidive' 操作 'iptables-multiport'”

我的 fail2ban.log 中有很多这样的错误

fail2ban.actions        [13370]: ERROR   Failed to execute ban jail 'recidive' action 'iptables-multiport' info 'CallingMap({'ip': '164.132.49.140', 'matches': '2019-04-01 08:30:14,100 fail2ban.actions        [1415]: NOTICE  [sshd] Ban 164.132.49.140\n2019-04-01 23:08:43,345 fail2ban.actions        [26861]: NOTICE  [sshd] Ban 164.132.49.140\n2019-04-01 08:30:14,100 fail2ban.actions        [1415]: NOTICE  [sshd] Ban 164.132.49.140\n2019-04-01 23:08:43,345 fail2ban.actions        [26861]: NOTICE  [sshd] Ban 164.132.49.140', 'ipmatches': <function Actions.__checkBan.<locals>.<lambda> at 0x7fa4a8366598>, 'time': 1554154478.985568, 'ipjailfailures': <function Actions.__checkBan.<locals>.<lambda> at 0x7fa4a8366510>, 'ipfailures': <function Actions.__checkBan.<locals>.<lambda> at 0x7fa4a8366488>, 'failures': 4, 'ipjailmatches': <function Actions.__checkBan.<locals>.<lambda> at 0x7fa4a8366400>})': Error starting action

我看到这是一个单行错误,但在我看来,模式匹配存在错误,或者日志中的其他内容导致了循环,因为模式现在甚至匹配错误行。

编辑我在日志中发现这些行可能与错误有关

2019-04-01 23:44:35,895 fail2ban.action         [19570]: ERROR   iptables -w -n -L INPUT | grep -q 'f2b-recidive[ \t]' -- stdout: b''
2019-04-01 23:44:35,896 fail2ban.action         [19570]: ERROR   iptables -w -n -L INPUT | grep -q 'f2b-recidive[ \t]' -- stderr: b''
2019-04-01 23:44:35,897 fail2ban.action         [19570]: ERROR   iptables -w -n -L INPUT | grep -q 'f2b-recidive[ \t]' -- returned 1
2019-04-01 23:44:35,898 fail2ban.CommandAction  [19570]: ERROR   Invariant check failed. Trying to restore a sane environment
2019-04-01 23:44:36,114 fail2ban.action         [19570]: ERROR   iptables -w -N f2b-recidive
iptables -w -A f2b-recidive -j RETURN
iptables -w -I INPUT -p all -m multiport --dports 0:65535 -j f2b-recidive -- stdout: b''

这是我在 jail.local 中的重复定义

[recidive]

enabled  = true
logpath  = /var/log/fail2ban.log
filter   = recidive
findtime = 86400
maxretry = 2
bantime  = 648000
protocol = all

我的 filter.d/recidive.conf 有这一行

failregex = ^(%(__prefix_line)s| %(_daemon)s%(__pid_re)s?:\s+)NOTICE\s+\[(?!%(_jailname)s\])(?:.*)\]\s+Ban\s+<HOST>\s*$

这就是我所知道的全部内容了。

如果有用的话,我在使用 ubuntu 16.04。

问题是:如何调试配置错误,甚至如何恢复默认工作配置。我只有另一个自定义过滤器(pihole),我知道如何恢复它,但我不知道是否有类似重置 fail2ban 配置的方法

答案1

这实际上是我的解决方案。只有接下来的几个小时才能告诉我这是否真的是解决方案。

我停止了fail2ban

systemctl stop fail2ban

然后清空它的日志

echo > /var/log/fail2ban.log

然后action在我的 recidive 配置中添加了一个

action   = iptables-allports[name=recidive, protocol=all]

然后重启faiilban服务

systemctl start fail2ban

相关内容