Guides
fail2ban integration guides
Complete, tested setups for the services people most often protect with fail2ban. Each guide gives you the filter, the jail, the log path, a test command and the gotchas specific to that service.
Every guide below follows the same pattern: find the log line a failed login or attack produces, match it with a filter (stock or custom, tested with fail2ban-regex), enable a jail in /etc/fail2ban/jail.local or jail.d/, make sure the ban lands where the traffic actually flows, and verify with fail2ban-client status <jail>. If fail2ban isn't installed yet, start with install fail2ban.
SSH and the system#
sshd-session.Proxmox web UIBan brute force on the Proxmox VE login on port 8006, plus PBS and PMG.OpenWrt routersdropbear and LuCI jails on a router, nftables, and banIP as the lightweight option.Web servers and reverse proxies#
limit_req_zone, bad requests, forbidden, and a 404/401/403 filter.ApacheAll nine stock Apache jails, apache2 vs httpd log paths, the LogLevel trap, a 404 filter.Nginx Proxy ManagerNPM's own log format, a tested filter and bans in DOCKER-USER.TraefikAccess log setup, the traefik-auth modes, Docker Compose, real client IPs.CaddyA JSON access-log filter for client_ip and status codes with the ts epoch timestamp.CloudflareRestore real visitor IPs and ban at Cloudflare's edge with an API token, including Tunnel.Self-hosted apps#
Login failed in nextcloud.log, log paths for Docker, AIO and snap.VaultwardenThe stock vaultwarden filter, LOG_FILE, a stricter admin-page jail.JellyfinDenied-login filter and a setup that survives Jellyfin's daily log files.Home AssistantContainer and Core setups, the built-in IP ban, and Home Assistant OS limits.Gitea & ForgejoBan password spraying on self-hosted Git servers, including GitLab's stock filter.MySQL & MariaDBMake the database log failed logins, then ban password sprayers.Minecraft serversA tested filter for whitelist and session rejections in latest.log, and the limits for game servers.Mail and VoIP#
VPN#
Firewalls and ban actions#
Operations and integrations#
chain = DOCKER-USER, the nftables forward hook, reading container logs.AbuseIPDB reportingReport banned IPs automatically.Prometheus & GrafanaExporters and scripts for Prometheus, node_exporter and Zabbix.Web UI & dashboardsThird-party web interfaces, from Webmin to Docker-based UIs.Which guide do I need?#
- Your service runs in Docker (NPM, Vaultwarden, Nextcloud AIO, Jellyfin…): read the app's guide and Docker containers. A ban in the default
INPUTchain doesn't stop traffic Docker forwards to a container. - Your site is behind Cloudflare or another proxy: fail2ban must see the visitor's address, not the proxy's. Fix that first; see Cloudflare and fail2ban bans the proxy IP.
- On Ubuntu 24.04: the package sets
backend = systemdfor all jails, so every jail that reads a log file needsbackend = auto— all examples in these guides include it. - No guide for your app? Write a filter for its log line with the filter generator, test it, and follow writing a custom filter. The jail.local generator builds the jail.
FAQ#
How do I protect a new service with fail2ban?#
Find the log line the service writes on a failed login and confirm it contains the client IP. Write a filter whose failregex matches that line with <HOST> or <ADDR>, test it with fail2ban-regex <logfile> <filter>, then add a jail with enabled = true, the logpath, the port and backend = auto, and reload fail2ban.
Why does fail2ban ban IPs but my Docker app is still reachable?#
Docker forwards published ports to containers through the FORWARD chain, while fail2ban bans in INPUT by default. Use an iptables action with chain = DOCKER-USER, or an nftables chain on the forward hook, for every jail that protects a container.
Spotted something wrong or out of date? Tell us — every page is checked against the current fail2ban release.