Contents
Fail2Ban is a daemon that reads the logs your server writes, finds IP addresses with repeated failed logins, and blocks them at the firewall for a set time. It handles the aftermath of a brute-force attack (an attack that tries passwords one after another) once the attempts reach your own server.
This review is for people who run a Linux server with SSH open. After reading it, you can do the following:
- Enable the sshd jail on a test Linux machine and write your settings in
jail.local - Explain
bantime,findtime, andmaxretry, and useignoreipso you don’t lock yourself out - Check with
fail2ban-regexthat the filter picks up failed-login lines in your log, without blocking anyone - Use
fail2ban-client statusto see blocked IPs and unblock them
What Fail2Ban does
The README describes Fail2Ban as software that scans logs and bans IP addresses with too many failed login attempts. It bans by updating the system firewall rules so that new connections from those IPs are rejected.
- Log watching: It reads log files or the systemd journal. Settings for common services such as sshd and Apache come with it.
- Settings per jail: The watching unit for one service is called a jail. Each jail sets which log to read, which failures to count, and how long to block.
- Temporary blocks: A block ends on its own after a set time.
- Manual control: With
fail2ban-client, you can list blocked IPs, block one by hand, and unblock it.
maxretry.Network traffic
- The default action only blocks. In
jail.conf,actionisaction_, which calls only thebanaction. jail.confalso provides actions that send email, register an IP with Cloudflare, or report to blocklist.de or AbuseIPDB. They run only when you put them inactionyourself. If you do, IPs and part of the log leave your server.- The default for
usednsiswarn. When a log line holds a hostname, Fail2Ban resolves it to an IP through DNS and records a warning. - State stays on your machine. In
fail2ban.conf, the database is/var/lib/fail2ban/fail2ban.sqlite3and the log is/var/log/fail2ban.log.
Admin rights and requirements
- Admin rights: The daemon changes firewall rules, so it runs as root. The official systemd unit has no
User=line, so it starts as root.fail2ban-clienttalks to the daemon through a socket (/var/run/fail2ban/fail2ban.sock), so run it withsudo. - Python: The README requires Python 3.5 or later. Reading the journal also needs systemd 204 or later and the Python systemd bindings. If you install from a package, the package manager resolves the dependencies.
- OS: The README points to your Linux distribution’s packages. The repository also has config files for FreeBSD and macOS (
paths-freebsd.conf,paths-osx.conf), but this review covers Linux only. - Firewall: An external command such as
nft(nftables) oriptablesdoes the blocking. Fail2Ban does not drop packets itself.
Check the defaults
These values come from jail.conf and paths-debian.conf in version 1.1.1, released on August 15, 2026.
| Setting | Default | Meaning |
|---|---|---|
bantime |
10m | How long a block lasts |
findtime |
10m | The window in which failures are counted |
maxretry |
5 | Failures allowed before a block |
backend |
auto | How log changes are detected. You can choose pyinotify, polling, or systemd |
enabled |
false | Whether a jail is on. The [sshd] section does not set enabled = true either |
ignoreself |
true | The server’s own addresses are never blocked |
ignoreip |
empty (127.0.0.1/8 ::1 appears as a commented-out example) |
IPs that are never blocked |
You can write bantime and findtime with a unit, such as 10m. Read the rules as: an IP that fails maxretry times within the last findtime is blocked for bantime.
Defaults differ by distribution and version.
- The 1.1.1
jail.confincludespaths-debian.conf. According to the ChangeLog, with this file the blocking action (banaction) isnftables. You can change it injail.local. - In
paths-debian.conf, the sshd backend (sshd_backend) issystemd, which means it reads the journal. The ChangeLog also says 1.1.1 switched the sshd backend tosystemd. - The 1.1.0
paths-debian.confsets neitherbanactionnorsshd_backend. Older packaged versions have different defaults, so check yours withfail2ban-client version. - Distribution packages may ship their own config files. This review did not check which jails or defaults any package enables. Read the actual values with commands such as
fail2ban-client get sshd bantime, shown below.
Firewall actions and IPv6
- nftables action: It creates an
inettable (f2b-table), keeps blocked IPs in a set, and blocks them in a chain (f2b-chain) hooked toinput. It keeps separate sets for IPv4 and IPv6, and theip6settings apply to IPv6. The default block type (blocktype) isreject. - iptables action: It calls
iptablesfor IPv4 andip6tablesfor IPv6. The default block type isREJECT, which returnsicmp-port-unreachablefor IPv4 andicmp6-port-unreachablefor IPv6. - IPv6: The README says IPv6 address matching has been supported since v0.10.
The sshd jail sets port = ssh, so by default only connections to the SSH port are blocked. A blocked IP can still reach other ports.
Try it safely: run the sshd jail on a test Linux machine
Use a test Linux machine you built yourself, such as a virtual machine, and start from a state where a block does no harm. Prepare these two things first:
- A way to log in from the virtual machine’s console without SSH. It is your way back in if a mistake locks you out of SSH.
- The IP address of the machine you connect from over SSH, written down.
These steps come from the official manual pages, config files, and source. We have not yet confirmed the results on a real machine for this review. On-screen output may differ by version.
-
Install from packages. According to the official wiki, on Debian and Ubuntu it works like this, and the service starts automatically.
sudo apt install fail2ban fail2ban-client version -
Don’t edit
jail.confdirectly. The manual recommends leaving*.conffiles unchanged because they ship with the package, and an update may overwrite them. Put your settings in/etc/fail2ban/jail.local. In a.localfile, write only the settings you want to change. The rest comes from the.conffile.[DEFAULT] bantime = 10m findtime = 10m maxretry = 5 # Replace with the IP of the machine you manage from (192.0.2.10 is a documentation example) ignoreip = 127.0.0.1/8 ::1 192.0.2.10 [sshd] enabled = trueignoreiptakes IPs, CIDR ranges, and DNS names, separated by spaces or commas. A listed IP is never blocked, however many times it fails.ignoreselfis true by default, so the server’s own addresses are safe even if you don’t list them. Your admin machine is not covered, though. -
Check the syntax.
-tonly tests the configuration and blocks nothing.sudo fail2ban-client -t -
Check with
fail2ban-regexthat the filter picks up failed-login lines in your log. It blocks nothing and changes no firewall rule. Passsystemd-journalif your logs are in the journal, or the file path if they are in a file. The second argument,sshd, is the filter name.sudo fail2ban-regex systemd-journal sshd sudo fail2ban-regex /var/log/auth.log sshdThe
Lines:line at the end shows how many lines were read, ignored, matched, and missed. If your log has failed logins but the match count is 0, the log source or the filtermodedoes not fit. -
Load the settings.
sudo fail2ban-client reload -
Check that the jail is running.
sudo fail2ban-client status sudo fail2ban-client status sshdIf
sshdappears inJail listin the first output, the jail is on. The second shows the jail’s state:Currently failedis the number of failures being counted,Currently bannedis the number of blocked IPs, andBanned IP listlists them. A jail that reads the journal shows aJournal matchesline, and one that reads files showsFile list, so you can see which one it uses. -
Read back the values to confirm they are what you intended.
sudo fail2ban-client get sshd bantime sudo fail2ban-client get sshd findtime sudo fail2ban-client get sshd maxretry sudo fail2ban-client get sshd actions -
Try the blocking without a real attack. Block a documentation IP by hand, then unblock it.
192.0.2.99is a documentation address that no real device uses.sudo fail2ban-client set sshd banip 192.0.2.99 sudo fail2ban-client status sshd sudo nft list ruleset sudo fail2ban-client set sshd unbanip 192.0.2.99If the IP appears under
Banned IP listinstatus sshd, and thenft list rulesetoutput shows thef2b-tabletable with the blocked IP, the block reached the firewall. If you use the iptables action, check withsudo iptables -Sinstead. -
Last, from another machine you manage, whose IP is not in
ignoreip, makemaxretryfailed SSH logins to the test machine with a wrong password. That machine’s IP is then blocked. If the test machine allows only public-key login, a wrong password does not count as a failure, so allow password login for a test user first. Unblock it when you are done.sudo fail2ban-client set sshd unbanip <that machine's IP>
If you lock yourself out, log in from the virtual machine’s console and run sudo fail2ban-client unban <IP>. To unblock every blocked IP, use sudo fail2ban-client unban --all.
Common uses
| Goal | How |
|---|---|
| List the running jails | sudo fail2ban-client status |
| Show one jail’s state | sudo fail2ban-client status <jail> |
| Find which jails have blocked an IP | sudo fail2ban-client banned <IP> |
| Block an IP by hand | sudo fail2ban-client set <jail> banip <IP> |
| Unblock an IP by hand | sudo fail2ban-client set <jail> unbanip <IP> |
| Unblock everything in every jail | sudo fail2ban-client unban --all |
| Add an IP to the ignore list | sudo fail2ban-client set <jail> addignoreip <IP> |
| Apply edited config files | sudo fail2ban-client reload |
| Check the config syntax | sudo fail2ban-client -t |
| Test a filter | sudo fail2ban-regex <log> <filter name> |
set <jail> addignoreip changes only the running daemon. It is not saved to a config file, so write any IP you want protected after a restart in ignoreip in jail.local.
Make blocking stricter
- sshd
mode: The sshd filter hasnormal(the default),ddos,extra, andaggressive(all of them combined). Setmode = aggressiveunder[sshd]injail.localto change it. The stricter the mode, the more log lines count as failures. - Longer blocks:
jail.confhas a commented-out explanation of a setting (bantime.increment) that lengthensbantimeeach time the same IP is blocked again. If you use it, set an upper limit withbantime.maxtime.
How Fail2Ban differs from Suricata and SafeLine
| Fail2Ban | Suricata | SafeLine | |
|---|---|---|---|
| What it watches | Logs a service writes | Packets on the network | HTTP requests to a web app |
| Basis for a decision | How many failed logins or similar entries the log holds | Whether the contents of traffic match a rule | The contents of a request (is it an attack) |
| How it blocks | Adds a firewall rule | Drops traffic in IPS mode (needs setup) | Stops it at a proxy in front of the app |
| When it blocks | After failures are logged and reach the count | During the connection | Before the request reaches the app |
| Good for | Services that log failed logins, such as SSH | Monitoring a whole network | Protecting your own web app |
Fail2Ban decides after a failure reaches the log, so the first few attempts get through. It reads only what the log says and does not read the traffic itself. In return, it can stop one sign, repeated failed logins, without extra hardware. You can use it together with Suricata or SafeLine.
Cautions
- Install it only on servers you manage. Don’t read or change another person’s server logs or settings without permission.
- A wrong setting can lock out you or your legitimate users. Put your admin IP in
ignoreip, and keep a way in other than SSH, such as a console, before you turn it on. - Where many people share one IP, such as an office, a school, or a mobile carrier, one person’s failures can block everyone.
- Don’t put a wide range, or an IP an attacker could use, in
ignoreip. Listed addresses are never blocked, even when they attack. - Fail2Ban depends on logs. If the log isn’t written, the time format can’t be read, or the
backenddoesn’t match, failures are not counted. Usefail2ban-regexandstatusto confirm they are. - As long as password login is allowed, attack attempts will keep arriving. Public-key-only login or two-factor authentication is the real fix. Fail2Ban reduces how often attempts arrive and how much log they leave.
- Adding email or external reporting actions sends IPs and part of the log out. Check the destination and what is included before you add them.
- Versions can change the configuration. According to the ChangeLog, 1.1.1 rewrote the
iptablesaction, and your own actions built on it may stop working. Read the “Compatibility” section of the ChangeLog before you update.
Read next
Sources
- Official repository (README)github.com/fail2ban/fail2ban/blob/1.1.1/README.md
- License (COPYING)github.com/fail2ban/fail2ban/blob/1.1.1/COPYING
- ChangeLog (1.1.1)github.com/fail2ban/fail2ban/blob/1.1.1/ChangeLog
- Config file jail.conf (1.1.1)github.com/fail2ban/fail2ban/blob/1.1.1/config/jail.conf
- Config file paths-debian.conf (1.1.1)github.com/fail2ban/fail2ban/blob/1.1.1/config/paths-debian.conf
- Config file fail2ban.conf (1.1.1)github.com/fail2ban/fail2ban/blob/1.1.1/config/fail2ban.conf
- Action nftables.conf (1.1.1)github.com/fail2ban/fail2ban/blob/1.1.1/config/action.d/nftables.conf
- Action iptables.conf (1.1.1)github.com/fail2ban/fail2ban/blob/1.1.1/config/action.d/iptables.conf
- Manual page jail.conf(5)github.com/fail2ban/fail2ban/blob/1.1.1/man/jail.conf.5
- Manual page fail2ban-client(1)github.com/fail2ban/fail2ban/blob/1.1.1/man/fail2ban-client.1
- Manual page fail2ban-regex(1)github.com/fail2ban/fail2ban/blob/1.1.1/man/fail2ban-regex.1
- systemd unit template (fail2ban.service.in)github.com/fail2ban/fail2ban/blob/1.1.1/files/fail2ban.service.in
- Official wiki: How to install fail2ban packagesgithub.com/fail2ban/fail2ban/wiki/How-to-install-fail2ban-packages
- Release 1.1.1github.com/fail2ban/fail2ban/releases/tag/1.1.1
Checked on 2026-10-28
Similar tools
Lynis
Impact Local onlyAn auditing tool for Linux and other Unix-like servers. It checks the system's configuration and lists warnings and suggestions for hardening. It runs on the server you are checking.
- Purpose
- Audit
- Type
- Command line
- Difficulty
- Intermediate
- License
- CopyleftGPL-3.0
- Category
- Defense and hardening / Vulnerability scanning
SafeLine
Impact Reaches othersA self-hosted, reverse-proxy WAF that sits in front of your own web app, inspects incoming HTTP requests, and blocks attacks. You install it on your own Linux server with Docker.
- Purpose
- Defense
- Type
- Self-hosted server
- Difficulty
- Intermediate
- License
- CopyleftGPL-3.0
- Category
- Defense and hardening / Web security
Suricata
Impact Reaches othersAn intrusion detection and prevention engine (IDS/IPS) that matches network traffic against rules and records suspicious activity as alerts.
- Purpose
- Defense
- Type
- Self-hosted server
- Difficulty
- Intermediate
- License
- CopyleftGPL-2.0
- Category
- Network
Wazuh
Impact Local onlyA free security platform (SIEM/XDR) that collects logs, configuration, and vulnerability data from agents on your endpoints and shows it all in one dashboard.
- Purpose
- Defense
- Type
- Self-hosted server
- Difficulty
- Advanced
- License
- CopyleftGPL-2.0(一部の構成要素は Apache-2.0)
- Category
- Vulnerability scanning / Forensics