ubuntu – Fail2Ban正确尝试禁止IP但IP没有被禁止 – iptables链存在但不工作

在Ubuntu 14.04服务器上运行.

所以我已正确配置fail2ban来处理/var/log/auth.log以进行SSH登录尝试.

尝试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我仍然可以通过SSH登录而没有任何问题.

同样的故事适用于我所有的fail2ban监狱.以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,但链不能正常工作REJECT流量(如上所述).

更新:

如果我改变:

banaction = iptables-multiport

至:

banaction = iptables-allports

然后它似乎工作.这种变化的后果是什么?

似乎导致fail2ban禁止IP,因为SSH使用此allports它禁止该IP的每个端口.由于重复ssh登录失败,故意被禁止.还禁止其他所有服务.

fail2ban链未正确链接到INPUT和OUTPUT链.
请编辑您的问题并提供以下输出
iptables -n -L INPUT
iptables -n -L OUTPUT

以及所有的fail2ban链,我将能够更精确.

相关文章

目录前言一、创建Hadoop用户二、更新apt和安装Vim编辑器三、...
原文连接:https://www.cnblogs.com/yasmi/p/5192694.html ...
电脑重启后,打开VirtualBox,发现一直用的虚拟机莫名的消失...
参见:https://blog.csdn.net/weixin_38883338/article/deta...
Ubuntu 18.04 LTS 已切换到 Netplan 来配置网络接口。Netpla...
介绍每个 Web 服务都可以通过特定的 URL 在 Internet 上访问...