How to Install Fail2Ban on CentOS 8

Install Fail2Ban on CentOS 8

In this tutorial we will show you how to install fail2ban on CentOS 8. For those of you who didn’t know, Fail2ban  it is a security based application for your Unix based server. The fail2ban service is commonly used to protect your SSH and FTP from unauthorized connection. This apps runs as a daemon that uses python scripts to parse log files for system intrusion attempts and adds a custom rules to iptables configuration file to ban the access to certain ip addresses.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo’ to the commands to get root privileges. If you are ready open up your terminal and follow through this tutorial, and in less than 10 minutes you will install fail2ban on a CentOS 8 server.

Install Fail2Ban on CentOS 8

Step 1. First let’s start by ensuring your system is up-to-date.

Step 2. Installing Fail2ban on CentOS.

Install the Fail2ban package by running the following command:

Step 3. Configuring Fail2Ban.

For this tutorial, we will create a separate file called jail.local in the /etc/fail2ban/ directory as shown:

We explain the options in the above configuration:

  • ignoreip: specifies the list of IP addresses or hostnames not to ban.
  • bantime: specified the number of seconds that a host is banned for (i.e effective ban duration).
  • maxretry: specifies the number of failures before a host gets banned.
  • findtime: fail2ban will ban a host if it has generated “maxretry” during the last “findtime” seconds.
  • banaction: banning action.
  • backend: specifies the backend used to get log file modification.

Next, Start the service and make it start automatically every time you reboot your server:

Finally, you can monitor failed and banned IP addresses using the fail2ban-client. To view the current status of the fail2ban server, run the following command:

Congratulation’s! You have successfully installed fail2ban. Thanks for using this tutorial for installing fail2ban to protect SSH in CentOS 7 system. For additional help or useful information, we recommend you to check the official fail2ban website.