What fail2ban Actually Stops (and the Things It Was Never Going To)
fail2ban is the bouncer who throws out anyone who gets their name wrong three times. Useful, and not a security strategy. How to set up its SSH jail, check who it has banned, and know what it can't protect you from.
Silas Voss
4 min read
fail2ban is a bouncer. He stands at the door with a clipboard, and if you get your name wrong three times, you're out for an hour. Simple. Effective. A little bit smug.
What he is not is a security strategy. [Cut to a nightclub. The bouncer is carefully checking IDs at the front door. Behind him, through the open back window, a man climbs in with a ladder labelled "unpatched plugin". The bouncer does not turn around. He's very focused on the clipboard.]
So let's set up fail2ban properly, and then talk honestly about the window.
How it works
fail2ban reads your logs. When it sees the same IP fail too many times inside a time window, such as failed SSH logins, it adds a firewall rule banning that IP for a while. Each service it watches is a jail, with its own rules.
sudo apt install fail2ban # Debian, Ubuntu
sudo dnf install fail2ban # Fedora
Configure it the right way: jail.local
Never edit jail.conf. Package updates overwrite it, and your settings vanish like a bouncer at closing time. Create /etc/fail2ban/jail.local instead:
[DEFAULT]
bantime = 1h
findtime = 10m
maxretry = 5
ignoreip = 127.0.0.1/8 ::1 203.0.113.10
[sshd]
enabled = true
backend = systemd
maxretry = 5withinfindtime = 10m: five failures in ten minutes and you're out.bantime = 1h: banned for an hour. Bots move on to easier targets long before that.ignoreip: addresses that are never banned. Put your own office or home IP here (the example address above is a placeholder) so a fat-fingered password doesn't lock you out of your own server. It's very embarrassing to be thrown out of your own club.backend = systemd: on systems that log only to the journal, with no/var/log/auth.log(recent Debian, for example), fail2ban has to read from systemd. Without this line, the sshd jail can sit there watching an empty file, banning nobody, looking busy.
Some distro packages already set a sensible backend for you. Check what yours ships before overriding it. Then:
sudo systemctl enable --now fail2ban
sudo systemctl restart fail2ban
Check the clipboard
sudo fail2ban-client status
sudo fail2ban-client status sshd
The second command shows how many failures it has seen, how many IPs are banned, and the list itself. On any internet-facing server, give it a day and that list will be long. It's oddly satisfying. Like watching a spam folder fill up.
Banned yourself anyway? Lift it:
sudo fail2ban-client set sshd unbanip 198.51.100.7
What fail2ban actually stops
- Noisy brute force from one address. The bot hammering
root/admin123gets banned after five tries. - Log spam. Your auth logs go from ten thousand lines a day to a readable few hundred. Real problems become visible again.
- A bit of load. Fewer pointless handshakes.
What it was never going to stop
- Distributed guessing. A botnet with ten thousand addresses can try a few passwords from each one and never trip
maxretry. The bouncer sees ten thousand polite strangers. - Exploits. A bug that works on the first try, like a vulnerable web plugin or an unpatched service, never produces failed logins. Nothing to count, nothing to ban. That's the ladder at the back window.
- Stolen credentials. Someone with the right key or password succeeds first time, and the bouncer waves them in.
- Anything it doesn't watch. fail2ban only protects the services you've given jails, through logs it can actually read.
Where it really fits
If you followed our SSH hardening post (keys only, no passwords), brute-force SSH logins can't succeed anyway. fail2ban's job there is mostly about noise: cleaner logs, less load, fewer pages. That's genuinely useful. It's just not the wall.
The wall is:
fail2ban sits on top of those three as a polite extra.
What to do today
Keep the bouncer. Just don't forget to lock the back window.
Security
More like this
Security
Who Did That? Tracing sudo and Logins on a Linux Server
The config changed overnight and nobody did it. Everyone says so. The logs disagree. How to read sudo logs and login records, record whole sudo sessions, watch key files with auditd, and why the logs shouldn't only live on the box.
Security
How to Read a CVE Without Panicking: CVSS, KEV and EPSS Explained
A 9.8 CVE drops on a Friday and your group chat catches fire. Before you cancel the weekend, learn how to read a CVE: what the score measures, what it doesn't, and the two lists that tell you whether anyone is actually attacking it.
Security
nftables From Zero: A Linux Firewall You Can Actually Read
iptables rules read like a ransom note made from magazine letters. An nftables firewall reads like a list. Build a default-deny ruleset in one file, test it with a five-minute dead man's switch, and avoid the Docker trap.