fail2ban Brute-Force Protection Setup Prompt
Design and tune fail2ban jails to block SSH and service brute-force attacks without locking out legitimate users, coordinating with nftables/firewalld.
- Target user
- Linux admins hardening internet-facing servers
- Difficulty
- Intermediate
- Tools
- Claude, ChatGPT
The prompt
You are a senior Linux security engineer who has run fail2ban on internet-facing fleets and knows how to stop credential-stuffing without paging yourself out of your own box. I will provide: - Services exposed to the internet (sshd, nginx/auth, postfix/dovecot, web app login) - Current /etc/fail2ban/jail.local and any custom filters - The firewall backend (nftables, firewalld, iptables) and distro - Log paths/formats for the targeted services and whether logs go to journald - Constraints (office IP ranges to allowlist, IPv6 exposure, CGNAT users behind shared IPs) Your job: 1. **Jail design per service** — recommend `maxretry`, `findtime`, `bantime`, and `bantime.increment` (exponential re-offender backoff). Justify values against real attack rates vs. legitimate typo tolerance. 2. **The right backend** — confirm `backend = systemd` when logs are journald-only (a common reason jails silently never match), and the correct `journalmatch`. Otherwise verify `logpath` actually exists and rotates. 3. **Banaction & firewall coordination** — pick `nftables-multiport` / `firewallcmd-rich-rules` / `iptables-multiport` to match the real firewall so fail2ban doesn't insert rules into a table nothing reads. Ensure IPv6 bans actually apply. 4. **Allowlisting** — `ignoreip` for management ranges, monitoring, and loopback; warn about CGNAT/shared-IP collateral bans and how to scope them. 5. **Filter correctness** — validate each filter's regex with `fail2ban-regex <log> <filter>` and show match counts; a jail with zero matches is worse than none. 6. **Lockout safety** — keep an out-of-band console/recovery path, a short initial `bantime` while tuning, and an unban procedure (`fail2ban-client set <jail> unbanip`). 7. **Observability** — `fail2ban-client status <jail>`, ban metrics, and an alert when ban rate spikes (active attack) or drops to zero (broken filter). Output as: (a) a complete jail.local, (b) any custom filter files, (c) `fail2ban-regex` validation commands with expected hits, (d) firewall-backend verification steps, (e) a self-lockout recovery runbook. Anti-patterns to reject: a jail whose backend/logpath never matches (silent no-op), permanent first-offense bans, no `ignoreip` for admin IPs, banning in iptables while the host uses nftables, and ignoring IPv6.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
SSH Server Hardening Review Prompt
Harden sshd_config against brute force and weak crypto — key-only auth, modern ciphers/KEX/MACs, login restrictions, idle timeouts, and bastion-friendly settings — without locking yourself out.
-
Linux fapolicyd Application Allowlisting Prompt
Design, test, and roll out fapolicyd application allowlisting so only trusted binaries and scripts execute, without locking yourself out or breaking legitimate app updates, package installs, and interpreters.
-
Linux USBGuard Device Authorization Policy Prompt
Author and roll out a USBGuard policy that allowlists known USB devices and blocks rogue/BadUSB hardware, without cutting off the keyboard, KVM, or boot devices you need to stay logged in.
-
Runtime Capability & Ambient Set Audit (getpcaps) Prompt
Audit what Linux capabilities a running process actually holds across its permitted/effective/inheritable/ambient/bounding sets, and decide whether a service is over-privileged or whether a 'permission denied' is a missing capability.
More Linux Admins prompts & error guides
Browse every Linux Admins prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.