Skip to content
Go back

Is fail2ban Actually Working? Here's How to Check

By SumGuy 6 min read
Is fail2ban Actually Working? Here's How to Check

You installed fail2ban. Your SSH port is open to the internet. But is fail2ban actually catching attacks? Or is it sitting there, disabled?

Scary question. Here’s how to find out.

Quick Health Check

Terminal window
sudo systemctl status fail2ban
fail2ban.service - Fail2Ban Service
Loaded: loaded
Active: active (running)

OK, it’s running. But is it doing anything?

Terminal window
$ sudo fail2ban-client status
Status
|- Number of jail: 3
`- Jail list: sshd, recidive, syslog-auth

Good. Three jails are active. One of them is sshd. Now the real question:

How Many IPs Are Banned?

Terminal window
$ sudo fail2ban-client status sshd
Status for the jail: sshd
|- Filter
| |- Currently failed: 2
| |- Total failed: 1247
| `- Journal matches: 3890
`- Actions
|- Currently banned: 5
|- Total banned: 247
`- IP list: 192.168.1.100 203.0.113.50 198.51.100.44 ...

You’re banning people! 247 IPs have been blocked. 5 are currently banned.

If Currently banned: 0 and Total banned: 0, your jail isn’t catching anything. Time to debug.

Check a Specific Jail

Terminal window
$ sudo fail2ban-client status sshd

Show the actual banned list:

Terminal window
$ sudo iptables -L -n | grep -i fail2ban
Chain f2b-sshd (1 references)
target PROT opt source
DROP all -- 192.168.1.100 0.0.0.0/0
DROP all -- 203.0.113.50 0.0.0.0/0

These are the IPs that fail2ban blocked via iptables rules.

Check the Logs

fail2ban reads logs to find failed attempts. Verify it’s looking at the right file:

Terminal window
$ grep -i filter /etc/fail2ban/jail.local | head
[sshd]
enabled = true
logpath = /var/log/auth.log
maxretry = 5
findtime = 600
bantime = 3600

That’s the config. logpath = /var/log/auth.log means it reads /var/log/auth.log for SSH failures.

Check if that file exists and has content:

Terminal window
$ tail -20 /var/log/auth.log | grep -i failed
Apr 6 10:30:14 server sshd[12345]: Failed password for invalid user admin from 192.168.1.100 port 55555 ssh2
Apr 6 10:30:22 server sshd[12346]: Failed password for invalid user root from 203.0.113.50 port 55556 ssh2

Good. Login attempts are happening. fail2ban should be catching them.

Check fail2ban’s log:

Terminal window
$ tail -50 /var/log/fail2ban.log | grep Ban
2025-04-06 10:30:45,123 fail2ban.actions [12345]: NOTICE [sshd] Ban 192.168.1.100
2025-04-06 10:31:45,456 fail2ban.actions [12346]: NOTICE [sshd] Ban 203.0.113.50

If you see Ban lines, fail2ban is working.

Manual Test: Trigger a Ban

Try to SSH with a wrong password, repeatedly:

Terminal window
# From another machine or in a loop
for i in {1..10}; do
ssh -o StrictHostKeyChecking=no user@target <<< "wrongpassword" 2>/dev/null
done

Check if you’re banned:

Terminal window
$ sudo fail2ban-client status sshd
...
`- IP list: YOUR_IP_HERE

If your IP appears, fail2ban is working.

Unban yourself:

Terminal window
$ sudo fail2ban-client set sshd unbanip YOUR_IP

Common Misconfiguration Issues

1. Jail Not Enabled

/etc/fail2ban/jail.local
[sshd]
enabled = false # ← OOPS
# Check:
$ sudo fail2ban-client status
# sshd won't appear in the jail list

Fix:

Terminal window
sudo sed -i 's/enabled = false/enabled = true/' /etc/fail2ban/jail.local
sudo systemctl restart fail2ban

2. Wrong Log Path

/etc/fail2ban/jail.local
[sshd]
logpath = /var/log/secure # ← Wrong on Ubuntu (uses /var/log/auth.log)

Check your distro:

Terminal window
# Debian/Ubuntu
/var/log/auth.log
# RHEL/CentOS/Fedora
/var/log/secure

3. maxretry Too High

/etc/fail2ban/jail.local
[sshd]
maxretry = 50 # ← Attacker gets 50 tries before ban. That's a lot.

Recommended: 5-10. Set it:

/etc/fail2ban/jail.local
[sshd]
maxretry = 5

4. bantime Too Short

/etc/fail2ban/jail.local
[sshd]
bantime = 60 # ← Banned for only 60 seconds. Useless.

Better:

/etc/fail2ban/jail.local
[sshd]
bantime = 3600 # 1 hour
# or
bantime = 86400 # 1 day

Restart After Config Changes

Terminal window
sudo systemctl restart fail2ban

Verify:

Terminal window
$ sudo fail2ban-client status sshd

Monitor In Real-Time

Watch bans happen as they occur:

Terminal window
$ sudo tail -f /var/log/fail2ban.log | grep Ban
2025-04-06 10:45:23,789 fail2ban.actions [9999]: NOTICE [sshd] Ban 192.0.2.50
2025-04-06 10:45:31,234 fail2ban.actions [9999]: NOTICE [sshd] Ban 198.51.100.66

Or check every 10 seconds:

Terminal window
watch -n 10 'sudo fail2ban-client status sshd'

Unban an IP (Legitimate User Locked Out)

Terminal window
$ sudo fail2ban-client set sshd unbanip 203.0.113.50

Check it’s gone:

Terminal window
$ sudo fail2ban-client status sshd | grep IP
`- IP list: 192.168.1.100 198.51.100.44
# 203.0.113.50 is gone

Prevent Accidentally Banning Yourself

If you’re managing the server over SSH, add your IP to whitelist:

/etc/fail2ban/jail.local
[DEFAULT]
ignoreip = 127.0.0.1/8 ::1 YOUR.HOME.IP.HERE
[sshd]
enabled = true
logpath = /var/log/auth.log
maxretry = 5
bantime = 3600
findtime = 600

Restart:

Terminal window
sudo systemctl restart fail2ban

Now your home IP never gets banned, no matter how many times you mistype your password.

Advanced: Email Alerts on Ban

Configure mail action:

/etc/fail2ban/jail.local
[sshd]
action = %(action_mwl)s # Mail + ban + whois lookup
destemail = admin@example.com
sendername = fail2ban
mta = sendmail # or postfix, exim, etc.

When someone gets banned, you get an email.

Recidive Jail (Repeat Offenders)

If an IP gets banned multiple times, ban them longer:

/etc/fail2ban/jail.local
[recidive]
enabled = true
logpath = /var/log/fail2ban.log
action = %(action_mwl)s
bantime = 604800 # 7 days
findtime = 604800
maxretry = 5

Now, if an IP is banned in sshd five times in a week, they get a 7-day ban.

Verify Your Rules Are Actually Working

Generate a test attempt:

Terminal window
ssh invaliduser@localhost <<< "wrongpass" 2>/dev/null &
ssh invaliduser@localhost <<< "wrongpass" 2>/dev/null &
ssh invaliduser@localhost <<< "wrongpass" 2>/dev/null &
ssh invaliduser@localhost <<< "wrongpass" 2>/dev/null &
ssh invaliduser@localhost <<< "wrongpass" 2>/dev/null &
# (5+ attempts)
# Check ban
$ sudo fail2ban-client status sshd | grep "Your.IP"

If localhost appears, your filters are working.

Summary: The Checklist

If all boxes check, fail2ban is protecting you. If not, fix the config and test again.

Your 2 AM self—the one who’s about to get paged for a compromised SSH account—will be grateful.


Share this post on:

Send a Webmention

Written about this post on your own site? Send a webmention and it may appear here.


Previous Post
Sticky Bit, Setuid, Setgid: Linux Special Permissions Explained
Next Post
Diagnosing Slow Linux Boot with systemd-analyze

Related Posts