Fail2ban Jail Generator
Prepare a validated jail.local for SSH, Nginx, bots, or a custom filter.
-
1Enter data
Enter content, paste text or load a file from disk. -
2Click the button
The tool will immediately process your data in the browser. -
3Get the result
Copy the finished text or save the file to your device.
return "Result ready in 0.1s";
}
Advanced options
Before reloading the service, save the result as /etc/fail2ban/jail.local and test the configuration. Add your own address to ignoreip to avoid locking yourself out.
Rate this tool:
Related tools
Other tools you may find usefulFail2ban jail.local generator for SSH and web servers
Fail2ban Jail Generator creates a safe starting point for /etc/fail2ban/jail.local. It combines a filter, port, log source, retry threshold, observation window, ban duration, and trusted addresses. The tool only builds text: it writes nothing to the operating system, reloads no firewall, and executes no server command.
How a jail connects logs, filters, and actions
Fail2ban watches events from logpath or a journal backend. A filter recognizes failed attempts, and the jail counts them per address during findtime. Reaching maxretry invokes the configured ban action for bantime. Every part must match the target distribution, service, and log format.
| Directive | Purpose | Risk of a poor setting |
|---|---|---|
maxretry | Events allowed before a ban | A very low value blocks legitimate users |
findtime | Window used to count events | A short window misses slow attacks |
bantime | How long a block remains | A permanent ban complicates recovery |
ignoreip | Trusted IP and CIDR networks | A broad exception disables protection |
backend | How events are collected | The wrong backend never sees logs |
banaction | Firewall rule implementation | An incompatible action does not block traffic |
SSH, Nginx, and bot presets
The SSH preset selects the sshd filter, the ssh service, and a common /var/log/auth.log path. Some systems use /var/log/secure, while a systemd backend can interpret log sourcing differently. Nginx auth starts with the error log; botsearch examines requests in the access log. Confirm the real paths and the Fail2ban process permissions.
The strict preset lowers the threshold and extends observation and ban periods, but stricter is not automatically safer. Mobile users, offices behind shared NAT, and automation can create many legitimate failures from one address. Observe current logs and compare mistakes with attack patterns before increasing enforcement.
Validation that protects configuration structure
Jail and filter names are limited to safe characters. A port accepts service names or numbers separated by commas, and a log path must be absolute without newlines or .. segments. A modified Livewire request therefore cannot append another directive. The retry count is restricted to an integer from 1 through 100.
Durations accept a positive number with seconds, minutes, hours, days, weeks, months, or years; -1 is available for a permanent ban. Trusted entries must be valid IPv4, IPv6, or CIDR networks, with at most 50 entries. Hostnames are deliberately rejected because their resolution can change independently from this reviewed configuration.
Using ignoreip without removing protection
Adding an administrator address reduces self-lockout risk, but trusting an entire provider range creates a lasting gap. Use the narrowest justified prefix and document who owns it. Dynamic addresses need an emergency access procedure, not progressively broader exceptions.
Fail2ban supplements rather than replaces key authentication, disabled password login, and restricted privileged accounts. Keep client and host declarations organized in a separate SSH configuration file with reviewed host names, users, and identity keys. Administrative access and service ports must remain consistent with the host firewall.
Log backends and ban mechanisms
auto lets Fail2ban choose a method for following files. systemd reads service journal events, polling periodically checks files, and pyinotify responds to file-system events when its library is installed. Not every filter provides a useful journal match, so systemd mode must be tested on the actual host.
The selected UFW, iptables, nftables, or firewalld action must match the firewall that really controls traffic. An installed command does not prove that its rules are active. Infrastructure checks can be represented in a workflow made with the GitHub Actions Generator, but credentials and privileged command output must not leak to public CI logs.
Safe deployment and testing
- Test the filter with
fail2ban-regexagainst a representative log sample that contains no secrets. - Back up the active configuration and keep a second administrative session available.
- Save the reviewed result as
/etc/fail2ban/jail.localwith restricted write permissions. - Run
fail2ban-client -tand do not reload the service while it reports an error. - Reload Fail2ban, then inspect jail status, its log, and the resulting firewall rules.
Deploy this change separately from operating-system upgrades. Preserve a rollback route through the hosting console. Keep configuration and runbooks free of secrets, and exclude unnecessary local copies with a policy from the Gitignore Generator.
Monitoring after activation
An active status alone does not prove protection. Inspect filter matches, current bans, and log growth. No bans can mean a quiet service or a broken filter. A sudden flood can indicate an attack, a false match, or a threshold that is too low. Read metrics together with service and firewall logs.
Review ignoreip exceptions, filter versions, and log rotation regularly. Retest expressions after an application changes its log format. Fail2ban is reactive; patching, reducing exposed services, and using strong authentication remain the primary controls.
Frequently asked questions
Will the generator install or restart Fail2ban?
No. It creates text only. An administrator performs installation, testing, and reload after reviewing the output and preparing a recovery path.
Why might /var/log/auth.log fail?
The distribution may use /var/log/secure or keep events only in the system journal. Confirm the actual source and backend on the target host.
Should bantime be set to -1?
A permanent block can suit repeat offenders, but it raises the cost of a false match. Use it after observing filters and only with a tested manual unban procedure.
Can ignoreip contain a hostname?
This generator intentionally accepts only IP and CIDR values. A stable narrow address is easier to audit than a name whose records can change ownership or scope.
Does Fail2ban replace a firewall and SSH keys?
No. It reacts to log events. A firewall limits exposure, while keys and account policy protect authentication before the system starts counting failures.