Skip to content

Fail2ban

  • To make setup easier; set the following variables

Variables

F2BAPI_KEY="your_notifiarr_api_key_here"
F2B_HOST="$(hostname)"

Instructions

  1. Open a shell on the server where Fail2ban is installed.

  2. Change to the Fail2ban actions directory.
    Adjust the path if your installation is different.

cd /etc/fail2ban/action.d/
  1. Download the Notifiarr Fail2ban action file.
curl -o notifiarr.conf https://notifiarr.com/scripts/fail2ban/notifiarr.conf
  1. Configure the Notification - Option A: Edit the notifiarr.conf file and update the hostname and API key.
nano notifiarr.conf
  1. Configure the Notification - Option B: Use sed to Update the hostname and API key:

    # Replace `YOUR_SERVERNAME_HERE` with your server's hostname:
    sed -i "s/YOUR_SERVERNAME_HERE/${F2B_HOST}/g" notifiarr.conf
    # Replace `YOUR_NOTIFIARR_API_KEY_HERE` with your API key:
    sed -i "s/YOUR_NOTIFIARR_API_KEY_HERE/${F2BAPI_KEY}/g" notifiarr.conf
    
  2. Configure your jail.local file:

Open your jail configuration:

nano /etc/fail2ban/jail.local

Add notifiarr as an action to the relevant jails or default settings:

action = notifiarr[bantime="%(bantime)s", port="%(port)s", protocol="%(protocol)s"]
  1. Restart Fail2ban to apply the changes.
fail2ban-client restart