<\/span><\/h2>\n\n\n\nFail2ban is available in the default Ubuntu 20.04 repositories, you will just need to update Apt cache and install the fail2ban package.<\/p>\n\n\n\n
$ sudo apt update\n\n$ sudo apt install fail2ban<\/code><\/pre>\n\n\n\nFail2ban starts automatically after the installation, verify this by running:<\/p>\n\n\n\n
$ sudo systemctl status fail2ban<\/code><\/pre>\n\n\n\n<\/span> Step 2. Fail2ban Configuration<\/span><\/h2>\n\n\n\nYou can find the Fail2ban configuration files in the \/etc\/fail2ban <\/strong>directory.
Before you start editing the default settings, first you will need to make a copy of the \/etc\/fail2ban\/jail.conf<\/strong> file.<\/p>\n\n\n\n$ sudo cp \/etc\/fail2ban\/jail.conf \/etc\/fail2ban\/jail.local<\/code><\/pre>\n\n\n\nThen open the jail.local file using your text editor of choice.<\/p>\n\n\n\n
$ sudo nano \/etc\/fail2ban\/jail.local<\/code><\/pre>\n\n\n\nThe ignoreip <\/strong>directive is used to exclude IP addresses, subnets or IP ranges from getting banned. You can do that by removing the comment from the ignoreip <\/strong>line and adding the IP addresses at the end, that you want to exclude separated by space between them.<\/p>\n\n\n\nFor example, if you want to exclude the IP addresses 10.10.10.5 and 10.10.10.80 from being banned, add the IP addresses at the end of the line with space between.<\/p>\n\n\n\n
ignoreip = 127.0.0.1\/8 ::1 10.10.10.5 10.10.10.80<\/code><\/pre>\n\n\n\nChanging the ban settings can be done with the parameters bantime<\/strong>, findtime <\/strong>and maxretry<\/strong>.<\/p>\n\n\n\nbantime <\/strong>is the duration of the ban time for the banned IP addresses. By default, the value is 10 minutes, but it can be also set to a number of days. Using negative values for bantime<\/strong> makes the ban duration permanent.<\/p>\n\n\n\nThe other parameter findtime <\/strong>tells us the duration in which the failed attempts should happen before they get banned.<\/p>\n\n\n\nmaxretry <\/strong>value <\/strong>defines the number of failed login attempts that should be made in the duration defined in findtime<\/strong> to get the IP banned.<\/p>\n\n\n\n