Configure Fail2Ban
How to install and configure Fail2Ban for added security on a dedicated server.
Fail2Ban is a daemon that can be used to monitor the logs of services and ban clients that repeatedly fail authentication checks.
You will need to be using a Unix-based operating system such as Ubuntu.
Log in to your server as root
and execute apt install fail2ban
to install Fail2Ban. You can then execute systemctl start fail2ban
to enable the service.
To configure Fail2Ban, create local configuration files by executing cp /etc/fail2ban/fail2ban.conf /etc/fail2ban/fail2ban.local
and then cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
.
Creating local files is important to avoid overwriting data when you upgrade Fail2Ban.
Execute nano /etc/fail2ban/jail.local
to edit the local configuration file. You can then adjust the configuration accordingly, such as changing the maximum number of attempts or default ban time.
Once done, save the file and exit the editor.
Execute systemctl restart fail2ban
to apply the changes.
You can check the status of Fail2Ban by executing systemctl status fail2ban
and view the current jails by executing fail2ban-client status
.
Last updated