DropVPS Team
Writer: John hens
How to Install Fail2Ban on Centos 9

Table of Contents
Fail2Ban is a powerful security tool that protects your CentOS 9 server by blocking IPs that show suspicious or malicious behavior.
Step 1: Update Your System
Keeping your system updated ensures Fail2Ban installs smoothly and runs on the latest secure packages.
sudo dnf update -y
Step 2: Install EPEL Repository
Fail2Ban is available through the EPEL repository, so you must enable it before installation.
sudo dnf install epel-release -y
Step 3: Install Fail2Ban
Once the EPEL repo is enabled, you can install Fail2Ban directly using the package manager.
sudo dnf install fail2ban fail2ban-firewalld -y
Step 4: Start and Enable Fail2Ban Service
Enabling and starting the service ensures Fail2Ban launches automatically and actively monitors your server.
sudo systemctl enable --now fail2ban
Step 5: Create a Local Configuration File
Creating a local configuration file ensures your Fail2Ban settings remain safe during updates and allows you to manage security rules in a clean and organized way.
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
Edit the file to customize protection:
sudo nano /etc/fail2ban/jail.local
Step 6: Enable SSH Jail
Enabling the SSH jail helps prevent brute-force login attempts on your server.
sudo bash -c 'echo -e "[sshd]\nenabled = true" >> /etc/fail2ban/jail.local'
Step 7: Restart Fail2Ban to Apply Changes
Restarting Fail2Ban is necessary to load your updated configuration and ensure all new security rules take effect properly.
sudo systemctl restart fail2ban
Step 8: Verify Fail2Ban Status
Checking the status confirms Fail2Ban is running correctly and protecting your server.
sudo fail2ban-client status
Step 9: Check SSH Jail Status
This command shows how many IPs are banned and ensures the SSH jail is active.
sudo fail2ban-client status sshd