Fail2Ban正确地尝试禁止IP,但IP不被禁止 – iptables链存在,但无法正常工作

在Ubuntu 14.04服务器上运行。

所以我有fail2ban正确configuration为SSHlogin尝试处理/var/log/auth.log

在3次失败尝试中,我在fail2ban日志中看到了这一点:

 2014-11-19 15:22:56,822 fail2ban.actions: WARNING [ssh] Ban BANNED_IP_ADDY 

iptables -L显示这个链:

 Chain fail2ban-ssh (1 references) target prot opt source destination REJECT all -- BANNED_IP_ADDY anywhere reject-with icmp-port-unreachable RETURN all -- anywhere anywhere 

然而,从这个IP,我仍然可以通过SSHlogin没有任何问题。

同样的故事也适用于我所有的失败监狱。 Apache例如,我可以看到fail2ban正确地检测到日志并声称它禁止一个IP。 IP最终在iptables链中,但IP实际上并未被拒绝。

我在这种情况下有一种感觉,因为SSH不在标准端口上。 它在不同的港口。

所以,如果我强制ssh jail规则使用新的端口:

 [ssh] enabled = true port = 32323 filter = sshd logpath = /var/log/auth.log maxretry = 5 

然后我看到这个错误:

 2014-11-19 15:30:06,775 fail2ban.actions.action: ERROR iptables -D INPUT -p tcp -m multiport --dports 32323 -j fail2ban-ssh iptables -F fail2ban-ssh iptables -X fail2ban-ssh returned 400 2014-11-19 15:30:06,778 fail2ban.actions.action: ERROR iptables -N fail2ban-ssh iptables -A fail2ban-ssh -j RETURN iptables -I INPUT -p tcp -m multiport --dports 32323 -j fail2ban-ssh returned 400 2014-11-19 15:30:06,779 fail2ban.actions.action: ERROR iptables -n -L INPUT | grep -q 'fail2ban-ssh[ \t]' returned 100 2014-11-19 15:30:06,780 fail2ban.actions.action: CRITICAL Unable to restore environment 

如果我把它作为

  port = ssh 

然后,它正确进入iptables,但链不工作REJECTstream量(如上所述)。

更新:

如果我改变:

 banaction = iptables-multiport 

至:

 banaction = iptables-allports 

然后它似乎工作。 这种变化的影响是什么?

看来,导致fail2ban禁止一个IP,因为SSH这个allports它禁止该IP的EVERY端口。 由于反复的sshlogin失败,故意被禁止。 也被禁止在其他服务。

fail2ban链没有正确链接到您的INPUT和OUTPUT链。 请编辑你的问题,并提供输出:

 iptables -n -L INPUT iptables -n -L OUTPUT 

和所有fail2ban链,也可以更精确。