How to configure Fail2Ban with UFW

Configure Fail2Ban to use UFW as the ban action backend instead of iptables on Ubuntu and Debian systems.

How to configure Fail2Ban with UFW

Configure Fail2Ban to use UFW as the ban action backend instead of iptables on Ubuntu and Debian systems.

Prerequisites

  • Fail2Ban and UFW installed on Ubuntu or Debian.
  • UFW enabled and active.

Step-by-Step: Configure Fail2Ban to Use UFW

  1. Edit /etc/fail2ban/jail.local and set the ban action to ufw in the [DEFAULT] section:

    [DEFAULT]
    banaction = ufw
    banaction_allports = ufw
  2. Restart Fail2Ban to apply the new backend:

    sudo systemctl restart fail2ban

How to Verify Fail2Ban Uses UFW

When Fail2Ban bans an IP, UFW shows the ban rule in its rule list:

sudo ufw status

Check the Fail2Ban log for UFW action messages:

sudo tail -20 /var/log/fail2ban.log