How to Install Fail2ban on Ubuntu
Automatically block brute-force SSH and web login attempts by banning abusive IPs — with jails, whitelists and monitoring.
What Fail2ban does
The moment a server is reachable from the internet, automated bots start hammering it with login attempts. Fail2ban watches your log files, spots repeated failures from the same IP, and temporarily bans that address at the firewall. It's a simple, effective layer that dramatically cuts brute-force noise.
Step 1: Install
On Debian or Ubuntu:
sudo apt update
sudo apt install fail2banFail2ban starts automatically. Confirm it's running:
sudo systemctl status fail2banStep 2: Create a local config
Never edit jail.conf directly — it's overwritten on upgrades. Create a jail.local override instead:
sudo nano /etc/fail2ban/jail.local[DEFAULT]
# Ban for 1 hour after 5 failures within 10 minutes
bantime = 1h
findtime = 10m
maxretry = 5
# Never ban your own network
ignoreip = 127.0.0.1/8 192.168.1.0/24
# Use nftables (modern) or iptables
banaction = nftables-multiport
[sshd]
enabled = true
port = sshAdjust ignoreip to your LAN so you can't accidentally lock yourself out.
Step 3: Apply and verify
sudo systemctl restart fail2ban
sudo fail2ban-client status
sudo fail2ban-client status sshdThe sshd status shows currently failed and banned IPs. Within a day of internet exposure, you'll usually see bans accumulating.
Step 4: Escalating bans (recommended)
Repeat offenders should be banned for longer. Enable incremental banning in [DEFAULT]:
bantime.increment = true
bantime.factor = 2
bantime.maxtime = 1wNow a persistent attacker's ban time doubles each time, up to a week.
Step 5: Protect more than SSH
Fail2ban ships with filters for many services. Useful jails for a homelab:
- Nginx / Nginx Proxy Manager — ban IPs failing HTTP basic-auth or hitting bad URLs.
- Vaultwarden — a community filter bans failed master-password attempts.
- Home Assistant — ban repeated failed logins.
Each is a small [jail] block pointing at the right log path and filter.
Step 6: Managing bans
# Unban an IP you banned by mistake
sudo fail2ban-client set sshd unbanip 203.0.113.9
# See everything
sudo fail2ban-client statusImportant context
Fail2ban is a complement, not a replacement, for good security. The biggest wins are still:
- Disabling SSH password auth in favor of keys.
- Keeping services off the public internet behind a VPN where possible.
- Enabling two-factor authentication on exposed dashboards.
See the full home server security checklist for the complete picture.
Troubleshooting
- Locked yourself out — access via console/KVM and add your IP to
ignoreip. - No bans ever appear — confirm the log path matches your distro and the jail is
enabled = true. - Bans don't actually block — verify
banactionmatches your firewall backend (nftables vs iptables).
Next steps
Layer Fail2ban with a properly configured firewall and reverse proxy, then monitor ban activity over time in Grafana if you enjoy the visibility.
Related articles
The Home Server Security Checklist
A practical checklist to secure your home server: SSH hardening, firewall, updates, backups and safe remote access.
How to Set Up Jellyseerr for Media Requests
Give your household a clean way to request movies and shows that flow automatically into your Jellyfin or Plex library.
How to Set Up WireGuard VPN
Self-host a fast, modern WireGuard VPN so you can reach your entire homelab securely from anywhere — with wg-easy for a simple UI.