Fail2Ban 解锁 ipaddress

Joh*_*lia 13 iptables fail2ban

我每次都试图在不重新启动 Fail2Ban 的情况下解除对 IP 地址的阻止,这样做的最佳方法是什么?或者你能指出我有用指南的方向吗?

正如您在下面看到的,我尝试删除的 IP 地址是:89.31.259.161

# iptables -L -n

    Chain INPUT (policy DROP)
    target     prot opt source               destination
    fail2ban-apache-badbots  tcp  --  0.0.0.0/0            0.0.0.0/0           multiport dports 80,443
    fail2ban-httpd  tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:80
    fail2ban-sasl  tcp  --  0.0.0.0/0            0.0.0.0/0           multiport dports 25,465,143,220,993,110,995
    fail2ban-SSH  tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:22
    fail2ban-httpd  tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:443
    fail2ban-httpd  tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:80
    fail2ban-vsftpd  tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:21
    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           multiport dports 80,443,25,465,110,995,143,993,587,465,21,20,2855
    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0
    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:54000

    Chain FORWARD (policy DROP)
    target     prot opt source               destination

    Chain OUTPUT (policy ACCEPT)
    target     prot opt source               destination

    Chain fail2ban-SSH (1 references)
    target     prot opt source               destination
    RETURN     all  --  0.0.0.0/0            0.0.0.0/0

    Chain fail2ban-apache-badbots (1 references)
    target     prot opt source               destination
    RETURN     all  --  0.0.0.0/0            0.0.0.0/0

    Chain fail2ban-httpd (3 references)
    target     prot opt source               destination
    DROP       all  --  89.31.259.161        0.0.0.0/0
    DROP       all  --  89.31.259.161        0.0.0.0/0
    RETURN     all  --  0.0.0.0/0            0.0.0.0/0
    RETURN     all  --  0.0.0.0/0            0.0.0.0/0
    RETURN     all  --  0.0.0.0/0            0.0.0.0/0

Chain fail2ban-sasl (1 references)
target     prot opt source               destination
RETURN     all  --  0.0.0.0/0            0.0.0.0/0

Chain fail2ban-vsftpd (1 references)
target     prot opt source               destination
RETURN     all  --  0.0.0.0/0            0.0.0.0/0
Run Code Online (Sandbox Code Playgroud)

我能够运行:iptables -D fail2ban-httpd -s 89.31.259.161 -j DROP虽然这只删除了其中一行。

use*_*517 16

使用--line-numbersiptables的选项来获取一个列表,其中显示了链中规则的行号,例如

iptables -L fail2ban-SSH -v -n --line-numbers
Chain fail2ban-SSH (1 references)
num   pkts bytes target     prot opt in     out   source              destination
1       19  2332 DROP       all  --  *      *     193.87.172.171      0.0.0.0/0
2       16  1704 DROP       all  --  *      *     222.58.151.68       0.0.0.0/0
3       15   980 DROP       all  --  *      *     218.108.224.81      0.0.0.0/0
4        6   360 DROP       all  --  *      *     91.196.170.231      0.0.0.0/0
5     8504  581K RETURN     all  --  *      *     0.0.0.0/0           0.0.0.0/0
Run Code Online (Sandbox Code Playgroud)

然后iptables -D chain rulenum用来删除你不想要的,例如

iptables -D fail2ban-SSH 1
Run Code Online (Sandbox Code Playgroud)

将删除

1       19  2332 DROP       all  --  *      *     193.87.172.171      0.0.0.0/0
Run Code Online (Sandbox Code Playgroud)

来自上面示例的行。请注意,所有内容都已重新编号,因此您可以再次运行相同的命令以删除链中的新规则 1。


小智 7

根据我对Fail2ban 的经验,如果Fail2ban 服务在Ban Time 内重新启动,直接通过IPTABLES 取消禁止IP 地址将导致该IP 再次被Fail2ban 禁止。

话虽如此,解除被 Fail2ban 禁止的 IP 地址的最有效和最干净的方法是使用 fail2ban-client。

步骤 1:通过检查 Fail2ban 日志记下 Jail 名称

sudo zgrep 'Ban' /var/log/fail2ban.log
Run Code Online (Sandbox Code Playgroud)

示例输出:

2017-11-03 04:30:14,509 fail2ban.actions [25091]:通知 [nginx-badbots] Ban 47.15.15.49 2017-11-03 04:37:29,597 fail2ban.actions [27065]-nginx NOTICE [27065]禁止 103.31.87.187 2017-11-03 04:37:30,124 fail2ban.actions [27065]:通知 [nginx-badbots] 禁止 201.33.170.251 2017-11-03 04,365643204:3643204:36432 nginx-badbots] Ban 47.15.15.49 2017-11-03 04:38:06,754 fail2ban.actions [27065]: NOTICE [vsftpd] Ban 128.20.12.68

如果我们有兴趣取消禁止 IP 地址 - 128.20.12.68 - 那么 Jail 名称是 vsftpd。

第 2 步:使用 fail2ban-client 解禁 IP 地址。一般格式为:

sudo fail2ban-client set [JAIL] unbanip [xx.xx.xx.xx]
Run Code Online (Sandbox Code Playgroud)

现在,运行:

sudo fail2ban-client set vsftpd unbanip 128.20.12.68
Run Code Online (Sandbox Code Playgroud)

示例输出:

128.20.12.68

第 3 步:确认从 Fail2ban 日志中解禁

sudo tail -f /var/log/fail2ban.log
Run Code Online (Sandbox Code Playgroud)

示例输出:

2017-11-03 04:38:13,332 fail2ban.actions [27065]:通知 [vsftpd] 取消禁止 128.20.12.68