Unblock an ip address blocked by iptables
Found a nice article on serverfault.com describing how to easily remove a single rule iptables while it is running.
Use the
--line-numbers
option to iptables to get a listing which shows the line numbers for the rules in a chain e.g.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
Then use
iptables -D chain rulenum
to remove the ones you don’t want e.g.iptables -D fail2ban-SSH 1
would delete the
1 19 2332 DROP all -- * * 193.87.172.171 0.0.0.0/0
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.