
{{ $('Map tags to IDs').item.json.title }}
How to Install Fail2Ban
Fail2Ban is a powerful intrusion prevention software that protects your server from various attacks, such as brute-force attacks. It works by monitoring log files for malicious activity and subsequently banning the offending IP addresses. This tutorial will guide you through the installation and basic configuration of Fail2Ban.
1. Installing Fail2Ban
Depend on your Linux distribution, you can install Fail2Ban using the following package manager commands:
- For Ubuntu:
sudo apt update sudo apt install fail2ban
- For CentOS:
sudo yum install fail2ban
2. Configuring Fail2Ban
After installation, you will find the main configuration file at /etc/fail2ban/jail.conf
. However, it’s best practice not to edit this file directly. Instead, create a new configuration file:
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
This creates a local copy that will override options in the original configuration file.
2.1. Editing the Configuration
Open the jail.local
file for editing:
sudo nano /etc/fail2ban/jail.local
In this file, you can configure settings for different services you want to protect, such as sshd:
[sshd]
enabled = true
port = ssh
filter = sshd
logpath = /var/log/auth.log
maxretry = 5
This configuration enables Fail2Ban for SSH, specifying the number of failed login attempts before an IP is banned.
3. Starting and Enabling Fail2Ban
After configuring Fail2Ban, start the service with:
sudo systemctl start fail2ban
To enable it to start on boot:
sudo systemctl enable fail2ban
4. Checking Status
To verify that Fail2Ban is running and check its status, use:
sudo systemctl status fail2ban
You can also view banned IPs for a specific jail, such as sshd:
sudo fail2ban-client status sshd
5. Unbanning an IP Address
If you need to unban an IP address, you can do so with:
sudo fail2ban-client set sshd unbanip IP_ADDRESS
Replace IP_ADDRESS
with the actual address you want to unban.
6. Conclusion
By following this tutorial, you have successfully installed and configured Fail2Ban for better security on your Linux server. Fail2Ban provides a robust defense mechanism against unauthorized access attempts, helping protect critical services like SSH. Continue exploring additional features of Fail2Ban to further enhance your server security!