Handling malicious requests with fail2ban
I've been receiving a lot of malicious requests for a while now, so I decided to try out fail2ban as a possible solution.
I see fail2ban as nice to have tool that is useful to keep down the "noise", but I wouldn't rely on it for security. If you need a tool to block unauthorized attempts or monitor log files excessively, you are probably doing something wrong.
I'm currently using fail2ban 1.0.2-2 from Debian Bookworm. Unfortunatly, I quickly ran into a problem, fail2ban doesn't work out of the box with this version:
systemd[1]: Started fail2ban.service - Fail2Ban Service.
fail2ban-server[2840]: 2025-07-28 14:40:13,450 fail2ban.configreader [2840]: WARNING 'allowipv6' not defined in 'Definition'. Using default one: 'auto'
fail2ban-server[2840]: 2025-07-28 14:40:13,456 fail2ban [2840]: ERROR Failed during configuration: Have not found an y log file for sshd jail
fail2ban-server[2840]: 2025-07-28 14:40:13,456 fail2ban [2840]: ERROR Async configuration of server failed
systemd[1]: fail2ban.service: Main process exited, code=exited, status=255/EXCEPTION
systemd[1]: fail2ban.service: Failed with result 'exit-code'.
The good news is that this issue has already been addressed for Debian Trixie.
Since I prefer to manage my own configuration, I removed the default
file at /etc/fail2ban/jail.d/defaults-debian.conf
and
replaced it with a custom setup. To fix the earlier issue, I also added
a systemd backend to the sshd jail so it would stop expecting a
logpath.
Here's the configuration I'm using:
$ cat /etc/fail2ban/jail.d/custom.conf
[DEFAULT]
maxretry = 3
findtime = 24h
bantime = 24h
[nginx-bad-request]
enabled = true
port = http,https
filter = nginx-bad-request
logpath = /var/log/nginx/access.log
[nginx-botsearch]
enabled = true
port = http,https
filter = nginx-botsearch
logpath = /var/log/nginx/access.log
[sshd]
enabled = true
port = ssh
filter = sshd
backend = systemd
I like to make things explicit, so I did repeat some lines from the default jail.conf file. In the end, I'm quite happy with it so far. Soon after I set it up, fail2ban was already banning a few hosts.
$ sudo fail2ban-client status nginx-bad-request
Status for the jail: nginx-bad-request
|- Filter
| |- Currently failed: 42
| |- Total failed: 454
`- Actions
|- Currently banned: 12
|- Total banned: 39
Written on 2025-07-28. Last updated on 2025-08-03.