fail2ban 错误 Gentoo

fail2ban 错误 Gentoo

我最近安装了一台运行 Gentoo 的新 VPS(这是我第一次使用该发行版,因此请原谅我,因为这真的很容易),并且像我在其他服务器上安装的一样安装了 fail2ban。将其设置为通过 iptables 阻止主机,因为使用 ssh 登录失败次数过多。但是我遇到了一个奇怪的错误,我无法完全解决。

当我启动 fail2ban 时,错误日志中出现了以下几行

2009-11-13 18:02:01,290 fail2ban.jail   : INFO   Jail 'ssh-iptables' started
2009-11-13 18:02:01,480 fail2ban.actions.action: ERROR  iptables -N fail2ban-SSH
iptables -A fail2ban-SSH -j RETURN
iptables -I INPUT -p tcp --dport ssh -j fail2ban-SSH returned 100

如果我尝试强制禁止,这些错误会显示在日志中,并且主机不会被禁止

2009-11-13 11:23:26,905 fail2ban.actions: WARNING [ssh-iptables] Ban XXX.XXX.XXX.XXX
2009-11-13 11:23:26,929 fail2ban.actions.action: ERROR  iptables -n -L INPUT | grep -q fail2ban-SSH returned 100
2009-11-13 11:23:26,930 fail2ban.actions.action: ERROR  Invariant check failed. Trying to restore a sane environment
2009-11-13 11:23:27,007 fail2ban.actions.action: ERROR  iptables -N fail2ban-SSH
iptables -A fail2ban-SSH -j RETURN
iptables -I INPUT -p tcp --dport ssh -j fail2ban-SSH returned 100
2009-11-13 11:23:27,016 fail2ban.actions.action: ERROR  iptables -n -L INPUT | grep -q fail2ban-SSH returned 100
2009-11-13 11:23:27,016 fail2ban.actions.action: CRITICAL Unable to restore environment

我的版本如下

Linux masked 2.6.18-xen-r12 #2 SMP Wed Mar 4 11:45:03 GMT 2009 x86_64 Intel(R) Xeon(R) CPU E5504 @ 2.00GHz GenuineIntel GNU/Linux
net-analyzer/fail2ban-0.8.4 
net-firewall/iptables-1.4.3.2

如果有人可以解释一下这些错误那就太好了,我确实想知道这是否是 iptables 或某些内核模块的问题,但如果我这样做了,我可以阻止 IP。

iptables -I INPUT -s 25.55.55.55 -j DROP

这让我觉得这有些不寻常。

提前致谢

答案1

在 Ubuntu 10.04 上,我在所有 jail 上随机遇到了类似的问题。有些可以启动,有些则不能。我通过编辑 /usr/bin 中的 fail2ban-client 文件并添加延迟解决了这个问题。现在每次我重新启动时它都可以完美运行。添加的行是 time.sleep(0.1)

def __processCmd(self, cmd, showRet = True):
    beautifier = Beautifier()
    for c in cmd:
        time.sleep(0.1)
        beautifier.setInputCmd(c)

答案2

该问题是由于 fail2ban 版本存在错误,它会同时向 iptables 发送多个命令。Ubuntu 10.04LTS 也受到影响。该问题描述于Debian 错误报告 554162

答案3

我最终通过将内核升级到 2.6.30 解决了这个问题

为此我遵循了本指南http://vps.net/forum/forums/tutorials-how-tos/1081-how-upgrade-gentoo-use-latest-pvops-kernel

Fail2ban 现在运行完美。

相关内容