Coding

Configure Fail2ban for Brute-Force Protection with Automatic 30-Minute IP Ban

by DHARMENDRA KUMAR · updated 10/1/2026

Prompt

Configure Fail2ban on my production Linux server to protect against brute-force attacks.

IMPORTANT REQUIREMENT:
Any IP banned by Fail2ban must be blocked for ONLY 30 MINUTES.

Set:

bantime = 30m
# equivalent to 1800 seconds

After 30 minutes, the IP must be automatically unbanned.

Requirements:

1. First inspect the server and existing Fail2ban configuration.
2. Do NOT overwrite or remove any existing working Fail2ban configuration without reviewing it.
3. Configure protection for SSH brute-force attacks.
4. Also inspect whether appropriate Fail2ban protection can be safely configured for Apache HTTP/HTTPS authentication/brute-force attempts.
5. Do NOT ban normal users simply because they generate 404, 403, or application errors.
6. Use conservative retry limits to reduce false-positive bans.
7. Configure every jail created by this task with:

   bantime = 30m

8. Do NOT configure:
   bantime = -1
   permanent bans
   extremely long bans
   incremental bans that can exceed 30 minutes

9. After configuration, validate Fail2ban configuration before restarting/reloading the service.

10. Show me:
   - which jails are enabled
   - findtime
   - maxretry
   - bantime
   - logpath used by each jail

11. Verify that the effective bantime is exactly 30 minutes.

12. Show commands for:
   - checking Fail2ban status
   - checking a specific jail
   - seeing currently banned IPs
   - manually unbanning an IP
   - checking Fail2ban logs

13. Do not modify firewall rules unrelated to Fail2ban.
14. Do not interrupt SSH access.
15. Before applying anything that could lock out the current administrator, verify the current SSH/admin IP and explain the change.

Goal:

Attacker repeatedly fails authentication
        ↓
Fail2ban detects repeated failures
        ↓
IP gets banned
        ↓
BAN FOR 30 MINUTES ONLY
        ↓
Fail2ban automatically unbans the IP

This is a production server, so inspect first, make the minimum required changes, validate the configuration, and then apply it safely.
Sign in to fork