Hostwinds Tutorials
Search results for:
Table of Contents
Fail2ban is a useful tool for further server hardening. It is not a replacement for disabling password authentication or changing the server's SSH port. Our guide on best security practices for a Linux server can guide you through those primary best practices.
This guide will cover installing Fail2ban and some initial configurations. Fail2ban will scan log files and ban malicious IP addresses. Fail2ban can then be used to auto-update firewall rules on the server to account for these IP addresses. There are filtering options for several services running on the system, including SSH servers, HTTP servers, FTP servers, Mail servers, and more.
Step 1: First, update the system and install the EPEL repository.
yum update
yum install epel-release
Step 2: Next, install Fail2Ban.
yum install fail2ban
Step 3: Finally, start, then enable Fail2Ban.
systemctl start fail2ban
systemctl enable fail2ban
Step 1: First, update the system.
apt-get update
apt-get upgrade -y
Step 2: Next, install Fail2ban.
apt-get install fail2ban
(Ubuntu Only)
Step 3: Finally, you will need to allow SSH access through UFW. Then enable the firewall:
ufw allow ssh
ufw enable
Step 1: First, update the system.
dnf update
Step 2: Next, install Fail2ban.
dnf install fail2ban
Step 3: Finally, start, then enable Fail2Ban.
systemctl start fail2ban
systemctl enable fail2ban
Step 1: Create a copy of fail2ban.conf named fail2ban.local.
cp /etc/fail2ban/fail2ban.conf /etc/fail2ban/fail2ban.local
You have now made a copy of the default configuration profile for Fail2ban. Fail2Ban will use the settings in fail2ban.local over the settings in fail2ban.conf, and fail2ban.conf should remain untouched.
Step 2: Create a copy of jail.conf named jail. local.
cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
Similarly, Fail2Ban will use the settings in jail. Local over the settings in jail. Conf, and jail. Conf should remain untouched.
fail2ban.local: Within fail2ban.local, you have the option to re-define values for the following:
jail. Local: Within jail. Local definitions under [DEFAULT] will define that option for every jail. Re-defining these options within each jail (i.e. [sshd]) will override the definition under [DEFAULT].
This means that the [apache-auth] jail can use the [DEFAULT] bantime, find time, and maxretry, while each of these can be re-defined under the [sshd] jail.
*Important note: By default, the enabled option under [DEFAULT] is set to false. This means all jails are disabled by default. Jails should be individually enabled by defining the enabled option in the specific jail:
enabled = true
Written by Benjamin Bream / December 9, 2019