Fail2Ban

A Linux daemon that reads your own server's logs and blocks IP addresses with repeated failed logins at the firewall for a set time.

cat fail2ban/meta.ymlChecked on 2026-10-28

Safety

Impact Local onlyStays on your machine and sends nothing out
Admin rights
Required
Test lab
Required

Usage

Purpose
Defense
Difficulty
Intermediate
Type
Self-hosted server
Platforms
Linux

Trust

Repository
fail2ban/fail2ban
License
CopyleftGPL-2.0-or-later
GitHub
stars19,0362026-11-17
Maintenance
Actively updatedLast update 2026-11-15
Contents
  1. Introduction
  2. What Fail2Ban does
  3. Network traffic
  4. Admin rights and requirements
  5. Check the defaults
  6. Try it safely: run the sshd jail on a test Linux machine
  7. Common uses
  8. How Fail2Ban differs from Suricata and SafeLine
  9. Cautions
  10. Read next
  11. Sources

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, and maxretry, and use ignoreip so you don’t lock yourself out
  • Check with fail2ban-regex that the filter picks up failed-login lines in your log, without blocking anyone
  • Use fail2ban-client status to 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.
What it doesn’t doFail2Ban can reduce how often failed logins arrive. It cannot fix weak authentication. The README also says to use two-factor or public-key authentication if you really want to protect a service. It counts failures per IP, so attempts spread across many IPs may never reach maxretry.

Network traffic

  • The default action only blocks. In jail.conf, action is action_, which calls only the banaction.
  • jail.conf also provides actions that send email, register an IP with Cloudflare, or report to blocklist.de or AbuseIPDB. They run only when you put them in action yourself. If you do, IPs and part of the log leave your server.
  • The default for usedns is warn. 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.sqlite3 and 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-client talks to the daemon through a socket (/var/run/fail2ban/fail2ban.sock), so run it with sudo.
  • 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) or iptables does 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.conf includes paths-debian.conf. According to the ChangeLog, with this file the blocking action (banaction) is nftables. You can change it in jail.local.
  • In paths-debian.conf, the sshd backend (sshd_backend) is systemd, which means it reads the journal. The ChangeLog also says 1.1.1 switched the sshd backend to systemd.
  • The 1.1.0 paths-debian.conf sets neither banaction nor sshd_backend. Older packaged versions have different defaults, so check yours with fail2ban-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 inet table (f2b-table), keeps blocked IPs in a set, and blocks them in a chain (f2b-chain) hooked to input. It keeps separate sets for IPv4 and IPv6, and the ip6 settings apply to IPv6. The default block type (blocktype) is reject.
  • iptables action: It calls iptables for IPv4 and ip6tables for IPv6. The default block type is REJECT, which returns icmp-port-unreachable for IPv4 and icmp6-port-unreachable for 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.

  1. 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
  2. Don’t edit jail.conf directly. The manual recommends leaving *.conf files unchanged because they ship with the package, and an update may overwrite them. Put your settings in /etc/fail2ban/jail.local. In a .local file, write only the settings you want to change. The rest comes from the .conf file.

    [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 = true

    ignoreip takes IPs, CIDR ranges, and DNS names, separated by spaces or commas. A listed IP is never blocked, however many times it fails. ignoreself is 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.

  3. Check the syntax. -t only tests the configuration and blocks nothing.

    sudo fail2ban-client -t
  4. Check with fail2ban-regex that the filter picks up failed-login lines in your log. It blocks nothing and changes no firewall rule. Pass systemd-journal if 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 sshd

    The 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 filter mode does not fit.

  5. Load the settings.

    sudo fail2ban-client reload
  6. Check that the jail is running.

    sudo fail2ban-client status
    sudo fail2ban-client status sshd

    If sshd appears in Jail list in the first output, the jail is on. The second shows the jail’s state: Currently failed is the number of failures being counted, Currently banned is the number of blocked IPs, and Banned IP list lists them. A jail that reads the journal shows a Journal matches line, and one that reads files shows File list, so you can see which one it uses.

  7. 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
  8. Try the blocking without a real attack. Block a documentation IP by hand, then unblock it. 192.0.2.99 is 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.99

    If the IP appears under Banned IP list in status sshd, and the nft list ruleset output shows the f2b-table table with the blocked IP, the block reached the firewall. If you use the iptables action, check with sudo iptables -S instead.

  9. Last, from another machine you manage, whose IP is not in ignoreip, make maxretry failed 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 has normal (the default), ddos, extra, and aggressive (all of them combined). Set mode = aggressive under [sshd] in jail.local to change it. The stricter the mode, the more log lines count as failures.
  • Longer blocks: jail.conf has a commented-out explanation of a setting (bantime.increment) that lengthens bantime each time the same IP is blocked again. If you use it, set an upper limit with bantime.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 backend doesn’t match, failures are not counted. Use fail2ban-regex and status to 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 iptables action, and your own actions built on it may stop working. Read the “Compatibility” section of the ChangeLog before you update.

Sources

  1. Official repository (README)github.com/fail2ban/fail2ban/blob/1.1.1/README.md
  2. License (COPYING)github.com/fail2ban/fail2ban/blob/1.1.1/COPYING
  3. ChangeLog (1.1.1)github.com/fail2ban/fail2ban/blob/1.1.1/ChangeLog
  4. Config file jail.conf (1.1.1)github.com/fail2ban/fail2ban/blob/1.1.1/config/jail.conf
  5. Config file paths-debian.conf (1.1.1)github.com/fail2ban/fail2ban/blob/1.1.1/config/paths-debian.conf
  6. Config file fail2ban.conf (1.1.1)github.com/fail2ban/fail2ban/blob/1.1.1/config/fail2ban.conf
  7. Action nftables.conf (1.1.1)github.com/fail2ban/fail2ban/blob/1.1.1/config/action.d/nftables.conf
  8. Action iptables.conf (1.1.1)github.com/fail2ban/fail2ban/blob/1.1.1/config/action.d/iptables.conf
  9. Manual page jail.conf(5)github.com/fail2ban/fail2ban/blob/1.1.1/man/jail.conf.5
  10. Manual page fail2ban-client(1)github.com/fail2ban/fail2ban/blob/1.1.1/man/fail2ban-client.1
  11. Manual page fail2ban-regex(1)github.com/fail2ban/fail2ban/blob/1.1.1/man/fail2ban-regex.1
  12. systemd unit template (fail2ban.service.in)github.com/fail2ban/fail2ban/blob/1.1.1/files/fail2ban.service.in
  13. Official wiki: How to install fail2ban packagesgithub.com/fail2ban/fail2ban/wiki/How-to-install-fail2ban-packages
  14. Release 1.1.1github.com/fail2ban/fail2ban/releases/tag/1.1.1

Checked on 2026-10-28

Similar tools

Lynis

Impact Local only
CISOfy/lynis

An 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
Actively updatedstars16,702Last update 2026-09-16
Read the Lynis review

SafeLine

Impact Reaches others
chaitin/safeline

A 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
Actively updatedstars23,297Last update 2026-11-11
Read the SafeLine review

Suricata

Impact Reaches others
OISF/suricata

An 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
Actively updatedstars6,901Last update 2026-11-15
Read the Suricata review

Wazuh

Impact Local only
wazuh/wazuh

A 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
Actively updatedstars17,780Last update 2026-11-17
Read the Wazuh review