I am trying to unblock an IP address without restarting Fail2Ban each time, what is the best way of doing this? Or can you point me in the direction of a useful guide?
As you can see below the IP address I am trying to remove is: 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
I was able to run: iptables -D fail2ban-httpd -s 89.31.259.161 -j DROP
although this only deleted one of the lines.
Use the
--line-numbers
option to iptables to get a listing which shows the line numbers for the rules in a chain e.g.Then use
iptables -D chain rulenum
to remove the ones you don't want e.g.would delete the
line from the example above. Note that everything is renumbered so you can run the same command again to remove the new rule 1 in the chain.
From my experience with Fail2ban, unbanning an IP address directly through IPTABLES will result in the IP being banned again by Fail2ban if the Fail2ban service is restarted within the Ban Time.
That being said, the most effective and clean way of unbanning an IP address banned by Fail2ban is using the fail2ban-client.
Step 1: Take note of the Jail Name by checking the Fail2ban log
Sample output:
If we are interested in unbanning the IP address - 128.20.12.68 - then the Jail name is vsftpd.
Step 2: Unban the IP address using fail2ban-client. The general format is:
Now, run:
Sample output:
Step 3: Confirm unban from Fail2ban log
Sample output: