To fix Fail2Ban ignoring your custom configuration, you must move your settings from the .conf files to .local files. Fail2Ban is designed to prioritize files ending in .local over the default .conf files; if you edit the defaults directly, updates to the package may overwrite your changes, or the system may ignore them if a corresponding .local file exists elsewhere in the priority chain.

What You'll Need

  • Root or sudo access to the Linux server.
  • A terminal emulator (SSH access).
  • A text editor installed on the server (such as nano or vim).
  • Basic familiarity with the Linux command line.

Step-by-Step

  1. Identify the configuration files. Fail2Ban stores its default configurations in /etc/fail2ban/jail.conf and various files in /etc/fail2ban/filter.d/. You should never edit jail.conf directly. Instead, you must create a file named jail.local in the same directory. The .local files act as an override layer; Fail2Ban reads the .conf file first and then applies any settings found in the .local file, which take precedence.
  2. Create your custom jail file. Use your preferred text editor to create the local override file. For example, run sudo nano /etc/fail2ban/jail.local. If you have already edited jail.conf, copy the specific lines you changed into this new jail.local file and then revert the changes in jail.conf to keep the system clean.
  3. Define the global settings. Inside jail.local, start with the [DEFAULT] section. This is where you set the baseline for all jails. Ensure you define the ignoreip setting to include your own IP address or local network range (e.g., ignoreip = 127.0.0.1/8 ::1) to prevent accidentally locking yourself out of the server. Also, set the bantime, findtime, and maxretry values here if you want them applied globally.
  4. Configure specific jails. Below the default section, enable the specific services you want to protect. For example, to protect SSH, add a section labeled [sshd]. Under this header, add enabled = true. If you are using a non-standard port for SSH, you must specify it here using port = yourportnumber, otherwise, Fail2Ban will look for the default port 22 and may fail to trigger the ban rules.
  5. Create custom filters if necessary. If you are protecting a custom application, you cannot simply enable a jail; you need a filter to tell Fail2Ban what a "failed login" looks like in the logs. Navigate to /etc/fail2ban/filter.d/ and create a new file ending in .conf (e.g., myapp.conf). Inside this file, define the failregex using regular expressions that match the error patterns in your application's log files.
  6. Link the custom filter to the jail. Go back to your jail.local file and create a section for your custom app. Specify the filter name (without the .conf extension), the path to the log file the application writes to, and set enabled = true. Example: [myapp] enabled = true port = http,https filter = myapp logpath = /var/log/myapp/access.log maxretry = 3
  7. Verify the configuration syntax. Before restarting the service, check for syntax errors. While Fail2Ban doesn't have a built-in "dry run" command for the whole config, you can test your custom regex filters using the fail2ban-regex tool. Run sudo fail2ban-regex /var/log/auth.log /etc/fail2ban/filter.d/sshd.conf to see if your rules actually match the lines in your log file.
  8. Restart the Fail2Ban service. For the changes in jail.local to take effect, you must restart the daemon. Use the command sudo systemctl restart fail2ban. If your system does not use systemd, use sudo service fail2ban restart.
  9. Confirm the jail is active. Use the Fail2Ban client tool to verify that your custom rules are loaded. Run sudo fail2ban-client status. This will list all active jails. Then, check a specific jail with sudo fail2ban-client status sshd to see the current number of banned IPs and the total number of failures detected.

Common Mistakes

One of the most frequent errors is editing jail.conf and expecting the changes to persist after a package update. When the Fail2Ban package is updated via the package manager, jail.conf is often overwritten, wiping out all custom rules. Always use jail.local.

Another common mistake is failing to account for the log file path. If the logpath specified in the jail does not exactly match the location where the application is writing logs, Fail2Ban will start the jail but will never find any failures to ban. This is especially common when using systemd-journald; in these cases, you must set backend = systemd instead of providing a logpath.

Users also frequently forget to update the port setting. If you have moved your SSH port to 2222 but leave the Fail2Ban config at the default port 22, the firewall rules created by Fail2Ban will block port 22, leaving your actual SSH port wide open to brute-force attacks.

Finally, incorrect regular expressions in custom filters are a major point of failure. A single misplaced character in a failregex can make the entire filter fail to match any lines, meaning no one will ever be banned regardless of how many times they fail to log in.

Tips

To keep your configuration organized, you can create a directory called /etc/fail2ban/jail.d/ and place multiple .conf files inside it (e.g., sshd.conf, apache.conf). Fail2Ban reads all files in this directory, allowing you to modularize your security rules rather than having one massive jail.local file.

Use the fail2ban-client set [jail] banip [ip] command to manually test your firewall rules. This confirms that the action part of your config (the part that actually talks to iptables or nftables) is working correctly, independent of the log-scanning part.

If you are managing multiple servers, consider using a configuration management tool to deploy your jail.local files consistently across your fleet. This prevents "configuration drift" where one server is more permissive than others.

Troubleshooting

If your rules are still being ignored, start by checking the Fail2Ban log file, usually located at /var/log/fail2ban.log. Look for lines containing ERROR or WARNING. If you see messages like "Found no reachable log file," it means your logpath is incorrect.

If the logs show that Fail2Ban is running but no one is being banned, use the fail2ban-regex tool. Run the tool against your log file using your custom filter file. If the output shows "0 matches," your regular expression is not matching the current format of your logs. You may need to update the regex to account for changes in the application's log output format.

Check if another firewall or security layer is overriding Fail2Ban. For example, if you are using a cloud provider's external firewall (like AWS Security Groups or DigitalOcean Firewalls), Fail2Ban's internal iptables rules will still work on the server, but they won't stop the traffic from hitting the server's network interface. Ensure your internal OS firewall (ufw or firewalld) is not conflicting with the rules Fail2Ban is trying to insert.

If the service fails to start entirely after a config change, check for trailing spaces or missing brackets in your jail.local file. A missing ] at the end of a section header will cause the parser to fail and the service to crash on startup.

Frequently Asked Questions

Why is Fail2Ban ignoring my changes in jail.conf?

Fail2Ban prioritizes .local files over .conf files. If a jail.local exists, or if the system is configured to look for overrides, the default jail.conf is treated as a baseline that can be superseded.

How do I check which config file Fail2Ban is actually using?

Fail2Ban doesn't have a single "active config" file; it merges them. You can see the final resulting configuration by using the command sudo fail2ban-client get-all, which dumps the current runtime settings.

Can I have multiple .local files?

Yes, you can use jail.local or create multiple files within the /etc/fail2ban/jail.d/ directory. All files in that directory are read and merged into the final configuration.

What is the difference between findtime and bantime?

findtime is the window of time Fail2Ban looks back at to count failures. bantime is the duration for which the IP is blocked after the maxretry limit is hit within that findtime window.

Does Fail2Ban work with systemd journals?

Yes, but you must specify backend = systemd in the jail configuration. When this is set, Fail2Ban queries the journal via the API instead of reading a physical file on disk.