Fail2Ban: already banned?

The recidive jail recommended in the other answer here did not fix the issue for me. I eventually fixed this, however, so here’s my method in case it helps others.

Fail2ban only blocks over TCP by default. At least with my setup, I noticed the “already banned” message was appearing when bots came back to try the blocked port over UDP instead.

To fix this issue, tell Fail2ban to block the port over all protocols instead of just TCP. You will need to make this change in /etc/fail2ban/jail.conf and in the [Init] section of every action you are using at /etc/fail2ban/action.d/.

Change this:

# Default protocol
protocol = tcp

To:

# Default protocol
protocol = all

Next, I disabled ICMP echo requests so blocked IPs had no way of hitting the server:

  1. nano /etc/sysctl.conf
  2. Add these two lines:

    net.ipv4.icmp_echo_ignore_all = 1  
    net.ipv4.icmp_echo_ignore_broadcasts = 1
    
  3. Exit and save the file.
  4. Run sysctl -p for the change to take effect.

After that, run fail2ban-client reload and you should not see these “already banned” messages any more unless you are spammed by an IP who gets a couple of access attempts before the block takes effect.

Also, it’s important to block all ports for every offender rather than the port they were trying to access by using the action iptables-allports in each of the Jails. Otherwise, they may trigger another Jail and end up as “already banned” in the logs.

Leave a Comment