Skip to content

Whitelist an IP Address in Fail2Ban

Steps
6
Category
Security
Covers
Fail2ban
On this page 6 steps

Fail2Ban is a powerful tool used to prevent unauthorized access to your server, typically by monitoring logs for too many failed login attempts and then banning the IP addresses associated with these attempts. However, sometimes legitimate users or services might get inadvertently blocked. To avoid this, it’s important to know how to whitelist (exclude) certain IP addresses. This article provides a step-by-step guide to help you whitelist an IP address in Fail2Ban.

Step 1 of 6Accessing Your Server

To manage Fail2Ban, you need to access your server. This is typically done via SSH (Secure Shell). Ensure you have administrative or root privileges, as modifying Fail2Ban configurations requires such permissions.

Step 2 of 6Identifying the Configuration File

Fail2Ban keeps its configuration in /etc/fail2ban. Inside this directory, you’ll find jail.conf. However, it’s recommended to create a local copy of this file named jail.local to override settings, as jail.conf may get overwritten during updates.

sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local 

Step 3 of 6Editing the Configuration File

Open jail.local using a text editor like nano or vim:

sudo nano /etc/fail2ban/jail.local

Step 4 of 6Whitelisting an IP Address

In the jail.local file, look for the [DEFAULT] section. To whitelist an IP address, add it to the ignoreip line. If the line doesn’t exist, you can create it.

For example, to whitelist the IP 123.45.67.89, you would add:


[DEFAULT]

ignoreip = 123.45.67.89

You can also add multiple IPs, separated by space, or use CIDR notation for a range of addresses.

After adding the IP addresses to the whitelist, save the file and exit the editor. In nano, this is done by pressing CTRL + X, then Y to confirm, and Enter to save.

Step 5 of 6Restarting Fail2Ban

For the changes to take effect, you need to restart the Fail2Ban service. This can be done with the following command:

sudo systemctl restart fail2ban 

Step 6 of 6Verifying the Whitelist

To ensure that your IP address has been successfully whitelisted, you can check the Fail2Ban log:

sudo fail2ban-client status 

This command will show you the status of Fail2Ban, including the list of currently banned and whitelisted IP addresses.

Conclusion

Whitelisting an IP address in Fail2Ban is a straightforward process that can save you from accidentally blocking legitimate users or services. Always ensure that you only whitelist trusted IP addresses, as this could potentially open a door for unauthorized access if used carelessly. With this guide, you should be able to safely and effectively manage the IP whitelist for your server’s Fail2Ban setup.

Rahul

Rahul Kumar is the founder and chief editor of TecAdmin.net. A Red Hat Certified Engineer (RHCE), he has worked in IT since 2009, with hands-on experience in Linux system administration, DevOps, web hosting, cloud platforms and automation. He started TecAdmin in 2013 to share practical, step-by-step guides, and leads its editorial work with one aim: making technical learning clear and useful for sysadmins, developers and beginners alike.

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top