TL;DR
fail2ban-client set [jail name] unbanip [the IP]
for instance
fail2ban-client set sshd unbanip 123.123.123.123
Details
It’s this time of the year again. Time to get a new VPS or dedicated server, put the latest LTS Ubuntu on it, and configure it as close as possible to the one I set up X years before in order to then migrate. Of course, usually, “as close as possible” still means finding wtf happened to the configuration options and features you were using before, if not wtf happened to whole pieces of software…
Anyhow, in this process, I sometimes get a bit lost in what accounts exist, what credentials they use and, after one too many tries, end up banned by fail2ban. I could just wait it out, but this time I figured, it’s my server I should unban myself damnit.
The short version is:
1) if you are the one banned, get an alternative access to the console. For instance you could use Webmin. Or a VPN, or your phone connection to log in to SSH from another IP.
2) list jail names:
fail2ban-client status
3) decide which one issued the ban (should be easy if you got your own self banned, otherwise see longer version below)
4) unban the IP:
fail2ban-client set [jail name] unbanip [the IP]
For instance, if you got banned while logging in to SSH from IP 123.123.123.123:
fail2ban-client set sshd unbanip 123.123.123.123
Longer version / some more details:
Check if the IP is banned in iptables (NB: for some reason, for me iptables didn’t list all the IPs that could be listed directly from fail2ban-client status [jail name]
, so if you can’t see the IP you’re looking for here here, I guess just move on to the other options):
iptables -n -L
and/or check the ban logs:
sudo zgrep 'Ban' /var/log/fail2ban.log*
(or just the latest logs, which should usually be enough)
sudo zgrep 'Ban' /var/log/fail2ban.log
(or just the end of it)
tail /var/log/fail2ban.log
The log should mention the jail name as well. If unsure, use fail2ban-client status
to list jail names.
You can also use fail2ban-client status sshd
to check the list of banned IPs for one particular jail (here sshd)
Sources
Fail2Ban: how to unban IPs that are blocked?
Linux: Iptables Find / Check Banned IP Address
0 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.