Use it to reduce brute-force attempts on exposed services, or when legitimate users get banned.
Fail2ban
Fail2ban watches logs for repeated failures (SSH, web logins) and bans the source address in the firewall for a time.
1. fail2ban-client status — jails active?
2. fail2ban-client status sshd — failures and banned IPs.
3. Unban: fail2ban-client set sshd unbanip <ip>.
4. Not banning → backend/logpath matches the service's log?
5. ignoreip includes admin networks.
failure logged → jail filter matches → count exceeds maxretry within findtime → firewall ban for bantime
For Security → Fail2ban, continue with the first unproven Topic check: Record exact host, distribution/kernel, boot ID, time window, workload, identity and the authoritative configuration/policy source for Fail2ban. If that boundary is healthy, advance to the adjacent check: Read back the effective runtime state and precedence rather than assuming an edited file, package state or service status is active. Preserve the same host/time/identity scope and rerun the original workload before accepting recovery.
Continue only after interpreting the current observation.Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Operational evidence path Verify boundary
application auth event → journal/log backend → filter match → counter/findtime → ban action → firewall backend → expiry/unban → service result
Healthy evidence: the intended jail is enabled, test failures match the filter, ban/unban state reaches the correct backend and legitimate service access remains healthy
Step 2 Verification and output interpretation Verify boundary
Verification chain. application auth event → journal/log backend → filter match → counter/findtime → ban action → firewall backend → expiry/unban → service result
Step 3 Commands Verify boundary
fail2ban-client status
fail2ban-client status sshd
fail2ban-client set sshd unbanip 10.0.0.5
Step 4 Failure modes and next checks Narrow the fault
Suspicious evidence: wrong backend/log path, regex drift, proxy address is banned, IPv6 is missed, action backend conflicts, whitelist is broad or repeated attacks evade per-source thresholds
Step 5 Common mistakes Narrow the fault
- Banning your own admin IP (use
ignoreip).
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
Configure jails in /etc/fail2ban/jail.local (not jail.conf). Whitelist management networks with ignoreip. Make sure the jail reads the right log or journal backend. It complements, not replaces, key-only SSH.
sestatus / aa-status— SELinux or AppArmor statess -tulpn— listening servicesjournalctl -u sshd -g 'Failed'— failed loginsausearch -m avc,user_login -ts today— audit events (auditd)
ReferenceImportant terms & boundaries5 sections · depth on demand
What this shows and what it does not
Fail2ban is confirmed only when the intended events are detected and the expected temporary action reaches the real firewall/service path; it does not establish prevention of distributed or credential-based attacks.
In depth
fail2ban: banning repeated offenders
fail2ban watches logs for repeated failures, such as failed SSH logins, and bans the offending addresses through the firewall for a while. The jail.conf(5) manual page describes the configuration:
- Files are read in the order
jail.conf,jail.d/*.conf,jail.local,jail.d/*.local, and later files override earlier ones. The.conffiles should stay untouched so upgrades are easy, with local changes in.localfiles. - A jail is enabled with
enabled = truein its section. - Each jail combines a filter (
filter.d/, regular expressions that find failures and extract the host), log sources and an action (action.d/, the commands that ban and unban).
Key options (manual)
| Option | Meaning |
|---|---|
maxretry | Failures needed within findtime to trigger a ban |
findtime | The window in which failures are counted |
bantime | How long a ban lasts |
ignoreip | Addresses and networks never banned (management networks) |
backend | auto by default; systemd reads the journal (and then takes journalmatch, not logpath) |
logpath | Log files to watch (non-systemd backends) |
banaction | The firewall action (default iptables-multiport; nftables actions exist) |
A typical jail.local
host$ sudo tee /etc/fail2ban/jail.local >/dev/null <<'EOF'
[DEFAULT]
ignoreip = 127.0.0.1/8 ::1 10.99.0.0/24
bantime = 1h
findtime = 10m
maxretry = 5
banaction = nftables-multiport
backend = systemd
[sshd]
enabled = true
EOF
host$ sudo systemctl restart fail2ban
host$ sudo fail2ban-client status sshd
Status for the jail: sshd
|- Filter
| |- Currently failed: 3
| `- Total failed: 412
`- Actions
|- Currently banned: 7
`- Banned IP list: 198.51.100.23 203.0.113.77 ...
host$ sudo fail2ban-client set sshd unbanip 203.0.113.77
host$ sudo nft list ruleset | grep -A3 f2b
host$ fail2ban-client --str2sec 1d12h
What fail2ban does and doesn't do
| It helps against | It doesn't help against |
|---|---|
| Noisy brute-force attempts from single addresses | Distributed attacks from many addresses |
| Log noise | Valid stolen credentials |
| Simple scanners | Attacks on services without a filter |
Key-only SSH authentication already makes password guessing useless. fail2ban then mainly reduces noise and load. Always put your own management networks in ignoreip, so a mistyped password doesn't lock out the administrators.
Documented example, not captured output.
How it works at runtime
Fail2ban is part of Security → Fail2ban. Fail2ban observes authentication/application logs and applies temporary actions such as source-address firewall bans after configured thresholds, reducing repeated automated abuse without replacing authentication hardening.
Topic-specific state model. Fail2ban observes authentication/application logs and applies temporary actions such as source-address firewall bans after configured thresholds, reducing repeated automated abuse without replacing authentication hardening.
Interpretation rule. - A banned address ≠ an attacker identity or evidence that an account is safe.
- Fail2ban service active ≠ the intended jail sees the correct current log source and action backend.
Quick reference
Fail2ban watches logs for repeated failures and bans source IPs via the firewall.
# /etc/fail2ban/jail.local
[DEFAULT]
bantime = 1h
findtime = 10m
maxretry = 5
backend = systemd
banaction = nftables-multiport
[sshd]
enabled = true
fail2ban-client status sshd
fail2ban-client set sshd unbanip 203.0.113.7
fail2ban-regex /var/log/auth.log /etc/fail2ban/filter.d/sshd.conf
Use jail.local (not jail.conf) for changes. Fail2ban reduces noise and brute-force attempts but does not replace key-only SSH and network restrictions; whitelist admin networks with ignoreip.
Limits and how it fails
Primary failure point. Fail2ban is confirmed only when the intended events are detected and the expected temporary action reaches the real firewall/service path; it does not establish prevention of distributed or credential-based attacks.
Fail2ban acts on observed authentication patterns and network banning; it does not fix authentication policy.
ReferenceConfiguration & state1 section · depth on demand
Configuration, persistence and lifecycle
Distribution/platform context. Fail2ban owns log-driven response automation; authentication service, Logging and Firewall branches own their underlying state.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Security → Fail2ban. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://docs.kernel.org/security/index.html · confidence 94%What changed and what may be affected
Recent technical edits are separated from ordinary page timestamps. Relationship impact is advisory: it identifies nearby canonical references to review, not automatic breakage.
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.
Quick lookup tables
Fail2ban operational reference
Topic-specific lookup boundaries, proof limits and next-step Evidence for Fail2ban.
| Lookup boundary | Topic-specific reference | Operational use |
|---|---|---|
| Scope / effective state | Fail2ban observes authentication/application logs and applies temporary actions such as source-address firewall bans after configured thresholds, reducing repeated automated abuse without replacing authentication hardening. | Establish exactly what this Topic owns before crossing into another subsystem. |
| Fast verification | Pin host + boot/time + real identity/workload → identify authoritative policy/key/trust source → read back loaded/effective runtime state → reproduce one safe allow/deny/handshake test → correlate audit/service/kernel evidence → locate first failed boundary → make the smallest persistent change → repeat original workload + regression/recovery check. | Use the shortest evidence path first; a fast check is a boundary test, not blanket proof. |
| Verification chain | application auth event → journal/log backend → filter match → counter/findtime → ban action → firewall backend → expiry/unban → service result | Trace requested/configured state through effective state to the observed workload result. |
| Failure boundary | Fail2ban is proven only when the intended events are detected and the expected temporary action reaches the real firewall/service path; it does not establish prevention of distributed or credential-based attacks. | Stop broad troubleshooting at the first boundary that is not supported by evidence. |
| Positive evidence | Correlated Linux security/trust evidence can establish this proof path: application auth event → journal/log backend → filter match → counter/findtime → ban action → firewall backend → expiry/unban → service result | Use this observation only for the specific claim it actually supports. |
| Evidence limit | It does not independently prove unobserved identities, objects, policies, namespaces, endpoints or time periods. Fail2ban is proven only when the intended events are detected and the expected temporary action reaches the real firewall/service path; it does not establish prevention of distributed or credential-based attacks. | Do not promote a local success signal into end-to-end or adjacent-dependency proof. |
| Next troubleshooting check | Continue from the first unproven security/trust boundary, capture the adjacent effective state and audit/handshake evidence, make only the demonstrated persistent change, then repeat the original workload plus recovery/regression checks. | Continue to the next unresolved boundary while preserving the original test condition. |
Fail2ban · operational reference
Compact Linux state, persistence, verification and boundary reference for fast lookup.
| Reference boundary | Fail2ban |
|---|---|
| Topic path | Security → Fail2ban |
| Runtime state | Fail2ban observes authentication/application logs and applies temporary actions such as source-address firewall bans after configured thresholds, reducing repeated automated abuse without replacing authentication hardening. |
| Fast checks | - Record exact host, distribution/kernel, boot ID, time window, workload, identity and the authoritative configuration/policy source for Fail2ban. - Read back the effective runtime state and precedence rather than assuming an edited file, package state or service status is active. - Reproduce one safe allowed/denied or handshake/access test and correlate kernel/service/audit evidence at the first relevant boundary. - Apply the smallest persistent cause-specific change, then repeat the original test plus an adjacent regression/recovery check. |
| Verification chain | application auth event → journal/log backend → filter match → counter/findtime → ban action → firewall backend → expiry/unban → service result Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return/regression → explicit Evidence boundary. Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return path or regression → explicit Evidence boundary. |
| Failure boundary | Fail2ban is proven only when the intended events are detected and the expected temporary action reaches the real firewall/service path; it does not establish prevention of distributed or credential-based attacks. Boundary chain: process/context → userspace configuration → kernel subsystem/resource → device/network/filesystem dependency → effective state → original workload. |
| Persistence rule | Prove which configuration source owns the state, then prove that the running consumer loaded or generated the intended state. |