Introduction

Every public web server is bombarded with thousands of unauthorized login attempts daily from automated botnets.

Even if your passwords are secure, thousands of repeated authentication failures consume server CPU, exhaust system memory, and fill up disk logs.

Fail2ban is an open-source intrusion prevention framework that automatically scans system log files and bans malicious IPs at the Linux firewall level.

Here is how to configure Fail2ban to shield your SSH ports and WordPress login screens.

Fail2ban automated intrusion prevention and IP banning architecture
Fail2ban automated intrusion prevention and IP banning architecture

How Fail2ban Operates Under the Hood

Fail2ban runs as a lightweight daemon monitoring system logs (e.g. /var/log/auth.log or Nginx access logs).

When it detects repeated failed attempts from an IP within a defined time window (e.g. 5 failed logins within 10 minutes), it triggers an automated ban action.

It injects a temporary DROP rule directly into the kernel-level iptables or UFW firewall.

The attacking IP is completely blocked from connecting to your server for the ban duration (e.g. 24 hours or 1 week).

Configuring the SSH Jail (jail.local)

Never edit the default jail.conf file; always create a custom jail.local configuration to survive software updates.

Configure [sshd] with maxretry = 3 and bantime = 86400 (24 hours).

Set findtime = 600 so that 3 failures within 10 minutes triggers an immediate ban.

Whitelist your own static office IP in ignoreip so you never accidentally ban yourself during testing.

EXPLORE SPECIALIZED SERVICE

Server Security & Linux Administration

RECOMMENDED SERVICEServer Security & Linux AdministrationTailored engineering, complete client ownership & clean code.
DIRECT INQUIRYDiscuss Your Project ScopeGet a transparent quote and delivery timeline within 24 hours.

Protecting WordPress wp-login.php and xmlrpc.php

Fail2ban can monitor Nginx or Apache access logs for repeated HTTP 200/401 status requests on wp-login.php.

Create a custom filter /etc/fail2ban/filter.d/wordpress-auth.conf matching regex patterns for login failures.

When a bot tries dictionary attacks on your WordPress admin, Fail2ban drops the connection at the TCP network layer before WordPress or PHP ever runs.

This saves massive amounts of server RAM and protects your database from CPU overload.

Frequently Asked Questions

How do I unban an IP if I get locked out?: Connect from a different IP or web console and run: sudo fail2ban-client set [jail-name] unbanip [your-ip].

Does Fail2ban consume lots of server memory?: No, Fail2ban is an extremely lightweight Python daemon using under 30MB of RAM.

Can Fail2ban be combined with Cloudflare?: Yes, specialized Fail2ban action scripts can push IP bans directly to Cloudflare's edge firewall via API.

CONTINUE READING

Related Insights & Guides