Why Your Fail2Ban Isn't Blocking Attacks
I set up fail2ban on my server back on April 1, 2026. My configuration file had comments like "Block malicious User-Agent bots," "Block vulnerability scans," and "Block fake GoogleBot," and I honestly thought those three lines were doing all the heavy lifting. Today, I finally took a look at the status, and out of the five jails, the three protecting my web server hadn't caught a single thing in 161 days. Even weirder was that each one had a different reason for this.
Three Out of Five Jails Were Showing Zero
I checked the cumulative count for each jail using fail2ban-client status and added up the blocked records from the rotated logs to get the real picture of what was being blocked.
| Jail | Log Being Watched | Detections | Blocks (Total Period) |
|---|---|---|---|
| sshd | journal | 9,540 | 118 |
| apache-auth | error_log | 470 | 10 |
| apache-badbots | access_log | 0 | 0 |
| apache-botsearch | access_log | 0 | 0 |
| apache-fakegooglebot | access_log | 0 | 0 |
Now, zero isn't automatically a bad thing—it could mean there was nothing to block. So, I started by reading the access logs for the same period.
What Was in the Logs During That Time?
I parsed every single access log for the period between September 6th at midnight and September 9th at 5 PM, covering about 3.7 days. There were 314,551 requests coming in from 18,938 different IP addresses. Of those, 215,619 resulted in a 200 OK response, while 87,353 returned a 404 error. Those 404 errors were directed at 21,846 different URLs.
| Target Being Attacked | Number of Requests | Notes |
|---|---|---|
| /.git directory | 45,136 | Checking if the repository is still accessible |
| xmlrpc.php | 16,617 | 16,519 POST requests, 16,510 returned 200 |
| .env related files | 11,112 | Includes variations like .env.bak, .env.production, etc. |
| wp-login.php | 7,115 | 4,720 POST requests |
| phpMyAdmin paths | 110 | Includes variations in case sensitivity |

One single IP sent 15,212 requests over a three-hour window, and 15,199 of those resulted in a 404. It looks like they were just systematically hitting different URLs.
4,720 Login Attempts, Zero Successes
The 4,720 requests to POST /wp-login.php came from 776 different IP addresses. Looking at the referrers, damyo.net accounted for 2,041 requests, and kilho.org had 1,563. All 4,720 responses were a 200 status code. WordPress displays the login screen again with a 200 code if the login fails, and sends you to the admin area with a 302 if it succeeds. Since there wasn't a single 302, it means no successful breaches occurred.
For xmlrpc.php, 16,369 requests were hitting responses of either 419 or 421 bytes. This is a short XML response indicating an authentication failure. The result is the same here, but the sheer number of attempts was about 3.5 times higher than the login screen attempts.
Cause 1: The Filter Was Reading the Wrong Logs
I started by checking apache-botsearch. The beginning of this filter looked like this:
prefregex = ^%(_apache_error_client)s (?:AHd+: )?<F-CONTENT>.+</F-CONTENT>$
failregex = ^(?:File does not exist|script not found or unable to stat): <webroot><block>
webroot = /var/www/The variable _apache_error_client expects a format like [client 1.2.3.4]. This specific format only appears in the error_log. However, my setup was pointing this filter at the access_log. Since the formats were completely different, it couldn't match anything. When I ran fail2ban-regex against 200,000 lines of access logs, it returned zero matches.
But that wasn't the end of it. The default webroot is set to /var/www/, but the actual document root on this server is /home/www/. Even if I fixed the log file path, the path mismatch would still result in zero matches. And thirdly, there were zero instances of "File does not exist" in the error_log. This is because WordPress handles 404 errors via PHP, not Apache, so Apache doesn't log a "file not found" error. All three conditions were misaligned.
Reason 2: The Bot Dictionary Was Outdated
The Apache BadBots list was fine when it came to interpreting dates. It recognized the date format across all 200,000 lines of access logs, but the failure patterns were zero.
So, I pulled out the 90 User-Agent entries in that filter and compared them against the logs.
| Name in Dictionary | Actual Top Bots in Logs | Requests in 3.7 Days |
|---|---|---|
| EmailSiphon | GPTBot/1.4 | 36,260 |
| Atomic_Email_Hunter/4.0 | SemrushBot/7~bl | 32,441 |
| DSurf15a 01 | Amazonbot/0.1 | 24,884 |
| Missouri College Browse | ClaudeBot/1.0 | 16,125 |
| Mac Finder 1.0.xx | MJ12bot/v1.4.8 | 7,150 |
There were 5,262 different User-Agents in the logs, and zero of them matched the 90 entries in the dictionary. The filter wasn't broken; it just didn't know what bots were actually showing up.
However, filling out the dictionary isn't the answer here. The top four bots listed above are search and AI crawlers, so blocking them would hurt indexing. I decided not to mess with the dictionary today, as adding entries means deciding which bots you're willing to ignore.
Reason 3: The Date Format Didn't Match the Filter
The apache-fakegooglebot rule was the most surprising one. The distribution's filter was set up like this:
failregex = ^s*<HOST> S+ S+(?: S+)?s+S+ "[A-Z]+ /S* [^"]*" d+ d+ ...
datepattern = ^[^[]*([{DATE}s*])Fail2Ban works by stripping out the part matched by the datepattern and then applying the failregex. However, this datepattern wraps the entire timestamp in brackets, causing the whole time notation to disappear. The resulting line looks like this:
Original 1.2.3.4 - - [09/Sep/2026:17:18:46 +0900] "GET / HTTP/1.1" 200 4795 ...
Remaining line 1.2.3.4 - - "GET / HTTP/1.1" 200 4795 ...The failregex is written assuming there are four tokens after the IP address. When the brackets are removed, there are only two, so it never matches. The fix was simple: if you just ran the 2,601 lines containing "Googlebot," they would all show zero hits. But when I swapped out just the datepattern with one from a different filter, it caught 2,581 hits. I didn't change any of the other conditions.
Why I Didn't Turn It On
I fixed it, but I didn't enable it. This specific rule is designed to flag every line that *claims* to be Googlebot, and then it uses reverse DNS lookups to filter out the real ones. Basically, the decision relies on external DNS checks. If those lookups fail even briefly, a genuine Googlebot might get flagged by the firewall.
When I checked, out of 114 IPs claiming to be Googlebot, 97 passed verification and 17 failed. Of those 17 failures, 11 were from Cloudflare ranges. From the firewall's perspective, traffic coming through Cloudflare looks like it's coming from the same range. Blocking those IPs would cut off visitors coming through that same path. Since I didn't believe this posed a risk to sites that are indexed, I set enabled = false and added a comment in the configuration file explaining why. It's more accurate to state that it's off than to leave it on and have it not work.
What I Changed
I tweaked three things. I moved the botsearch to the error log and corrected the webroot to the actual path. I also disabled fakegooglebot for the same reasons. Finally, I created a new jail to catch the actual attacks coming in.
[Definition]
failregex = ^<HOST> -.*"POST /+(?:wp-login.php|xmlrpc.php)
datepattern = ^[^[]*[({DATE})I wrote the failregex so it doesn't rely on the date's position. This way, I won't fall into the same trap I saw in Cause 3. Here are the values I set for the jail:
| Setting | Value | Reason |
|---|---|---|
| maxretry | 10 | 109 IPs accounted for 90.8% of all attempts, making over 10 tries in 10 minutes a key indicator. |
| findtime | 10 minutes | Lowering this to 3 attempts only bumped the catch rate from 90.8% to 94.1%, which wasn't worth the minor gain. |
| bantime | 1 hour | This is a generous enough window not to inconvenience legitimate users who might be typing their password in. |
| ignoreip | Cloudflare ranges | This prevents us from blocking legitimate visitors who are behind a proxy. |
I ran fail2ban-client --test to check the syntax and then restarted the service. Within 20 seconds, it detected 394 events and blocked the first IP. Running the filter against the entire access log would take 31,723 lines to process. This is the first time in 161 days that the count isn't zero.
Did My Prediction From Two Days Ago Come True?
I mentioned that fixing the duplicate entries in the access logs on September 7th would cut down on about 62.5MB per week. Since the same file contained both the day before the fix and the day after the fix, I could cross-check the data. I compared it against that calculation.
| Category | Sept 6 (Before Fix) | Sept 8 (After Fix) |
|---|---|---|
| Request Count | 77,757 | 109,419 |
| Log Size | 24,907,781B | 24,781,335B |
| Log Per Request | 320.3B | 226.5B |
If you multiply the request volume from September 8th by the pre-fix rate, you get 33.43MB. However, the actual usage was 23.63MB, which averages out to 9.79MB per day, or about 68.6MB monthly. This is higher than my predicted 62.5MB, but it's because the requests went up, not because the rate improved. The rate itself was consistent with my prediction.
The Step-by-Step Process for Checking This
Here is the exact sequence of steps I followed. If you have fail2ban running on any server, this whole check should take you about 15 minutes.
- Use
fail2ban-client statusto get the list of jails, and then runstatusfor each one to see the detection and ban counts. - If a jail shows zero activity, check the logs first. This helps you determine if nothing actually hit the server, or if something did hit it but the filter missed it.
- If the filter missed it, run the filter directly against the log file using
fail2ban-regex. This will also show you how many entries were recognized based on the date format. - If the dates are recognized but the failure pattern count is zero, it means the filter content doesn't match the log. If even the dates come up as zero, then the log format itself is different.
- Once you've fixed the filter, run
fail2ban-client --testto check the syntax before restarting, and then check after a few minutes to confirm the detection count actually goes up.
The third step is the most crucial. Before you test your filter against the live logs, the only proof that your configuration is correct is that "it says so." I initially guessed the cause of fakegooglebot differently, but this command proved me wrong. I first thought the issue was related to response bytes showing as -, but when I ran the test, the real culprit turned out to be the date format.
The Takeaway
The zero counts in those three instances were all due to different reasons. One was reading the wrong log file, another was using outdated bot lists, and the third had a mismatch between two lines inside the filter itself. The common thread? None of them threw an error.
The configuration was valid, the service was running fine, and the status output showed it had started up. There wasn't a single sign of trouble until I actually looked at the numbers.
This is especially true for settings, like the ones you might enable for bot blocking (check out the Bot Blocking Settings here), where you assume it's working just because it's turned on. If you never check the number of blocks it catches, you have no way of knowing the difference between what's happening and what isn't. I hadn't checked for 161 days. Moving forward, when I implement these kinds of settings, I plan to document what a normal count looks like. Having those baseline numbers is what lets you tell if a zero is a good sign or a bad sign.
