Fail2Ban取消阻止ipaddress

我试图在不重新启动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 

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

对iptables使用--line-numbers选项来获取列表,显示链中规则的行号

 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 

然后使用iptables -D chain rulenum删除那些你不想要的东西

 iptables -D fail2ban-SSH 1 

会删除的

 1 19 2332 DROP all -- * * 193.87.172.171 0.0.0.0/0 

来自上面的例子。 请注意,一切都重新编号,以便您可以再次运行相同的命令,以删除链中的新规则1。

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

这就是说,解除被Fail2ban禁止的IP地址的最有效和最干净的方法是使用fail2ban-client。

步骤1:通过检查Fail2ban日志logging监狱名称

 sudo zgrep 'Ban' /var/log/fail2ban.log 

示例输出:

2017-03-03 04:30:14,509 fail2ban.actions [25091]:NOTICE [nginx-badbots]禁止47.15.15.49 2017-11-03 04:37:29,597 fail2ban.actions [27065]:NOTICE [nginx-badbots]禁止103.31.87.187 2017-11-03 04:37:30,124 fail2ban.actions [27065]:NOTICE [nginx-badbots]禁止201.33.170.251 2017-11-03 04:37:30,364 fail2ban.actions [27065]:NOTICE [ nginx-badbots]禁止47.15.15.49 2017-11-03 04:38:06,754 fail2ban.actions [27065]:NOTICE [vsftpd]禁止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] 

现在运行:

 sudo fail2ban-client set vsftpd unbanip 128.20.12.68 

示例输出:

128.20.12.68

步骤3:从Fail2ban日志中确认unban

 sudo tail -f /var/log/fail2ban.log 

示例输出:

2017-11-03 04:38:13,332 fail2ban.actions [27065]:NOTICE [vsftpd] Unban 128.20.12.68