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.

Bash
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:

INI
[DEFAULT]
bantime  = 1h
findtime = 10m
maxretry = 5
ignoreip = 127.0.0.1/8 ::1 203.0.113.10

[sshd]
enabled = true
backend = systemd
  • maxretry = 5 within findtime = 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:

Bash
sudo systemctl enable --now fail2ban
sudo systemctl restart fail2ban

Check the clipboard

Bash
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:

Bash
sudo fail2ban-client set sshd unbanip 198.51.100.7

What fail2ban actually stops

  • Noisy brute force from one address. The bot hammering root/admin123 gets 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:

  1. Key-only SSH, so guessing is pointless.
  2. A default-deny firewall, so only the doors you chose exist. (See our nftables post.)
  3. Patching, so the back window's latch actually works. (See unattended-upgrades and needrestart.)

fail2ban sits on top of those three as a polite extra.

What to do today

  1. Write a jail.local with your own IP in ignoreip, and the systemd backend if your system needs it.
  2. Run fail2ban-client status sshd tomorrow and admire the list.
  3. Then check that the real wall is up: key-only SSH, a firewall and patching.

Keep the bouncer. Just don't forget to lock the back window.