loading

How to Secure Your Linux Server with Fail2Ban Configuration

Updated at
22/08/2023
Views
4920

Fail2Ban is a popular open-source tool used to protect Linux servers from brute-force attacks, password guessing, and other malicious activity. It works by monitoring log files for specific patterns of activity and then blocking IP addresses associated with that activity for a specified period of time.

Here are the steps to configure Fail2Ban on your Linux server:

1. Install Fail2Ban: Use the package manager of your Linux distribution to install Fail2Ban. For example, on Ubuntu, you can use the following command:

```
sudo apt-get install fail2ban
```

2. Configure the Jail: Fail2Ban uses a "jail" to define the settings for monitoring and blocking specific types of activity. The default jail configuration is located in `/etc/fail2ban/jail.conf`. Copy this file to `/etc/fail2ban/jail.local` to create a custom configuration:

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

3. Edit the Jail Configuration: Open `/etc/fail2ban/jail.local` in a text editor and configure the settings for the services you want to protect. For example, to protect SSH, add the following to the `[sshd]` section:

```
enabled = true
port = ssh
filter = sshd
logpath = /var/log/auth.log
maxretry = 5
banaction = iptables-multiport
bantime = 1h
```

This configuration will monitor the `/var/log/auth.log` file for SSH login attempts and block IP addresses that exceed 5 failed attempts within an hour.

4. Restart Fail2Ban: After editing the jail configuration, restart Fail2Ban to apply the changes:

```
sudo systemctl restart fail2ban
```

5. Verify Fail2Ban is Working: Check the Fail2Ban log file to verify that it is blocking IP addresses:

```
sudo cat /var/log/fail2ban.log
```

Fail2Ban is an effective tool for protecting your Linux server from malicious activity. By configuring Fail2Ban jails, you can monitor and block specific types of activity and ensure the security of your server.

YottaSrc footer

why choose us?

Better Pricing, Fast SSD Storage and Real 24/7
Technical Support.

control panel icon
cPanel

Managing Your Site Through CPanel With The Latest Version

security icon
FAST, RELIABLE & SECURE

99.8% Uptime Guarantee.
So Focus On Your Work!

support icon
24/7/365 Support

Day or night, rain or shine,
our team is here for you!

cloud backup icon
Daily Backup

Daily & Weekly Backup.
Your Files Are Safe!