- Hexzilla
- Posts
- ๐ก๏ธHow to Install and Configure Fail2ban on Linux | Protect Your Linux Server from Brute-Force Attacks
๐ก๏ธHow to Install and Configure Fail2ban on Linux | Protect Your Linux Server from Brute-Force Attacks
How to Install and configure Fail2ban on Linux
What is Fail2ban?
Fail2ban is a security tool ๐ that monitors your serverโs logs for suspicious activity (like failed login attempts) and bans IPs that show malicious behavior ๐ซ. Super useful for protecting services like SSH!
Step 1: Update your system ๐ง
First, ensure your system is up to date to avoid compatibility issues.
sudo apt update && sudo apt upgradeStep 2: Install Fail2ban โ๏ธ
Now, install Fail2ban from your package manager.
sudo apt install fail2banStep 3: Configure Fail2ban ๐ง
Copy default configuration file ๐
Before making changes, create a local copy to customize settings.
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.localEdit the configuration โ๏ธ
Open the
jail.localfile to adjust settings.
sudo nano /etc/fail2ban/jail.localSet ban time (how long an IP is banned):
bantime = 600 # Bans IP for 10 minutesMax retries (failed attempts before banning):
maxretry = 5 # After 5 failed login attempts, IP gets bannedWhitelist trusted IPs:
ignoreip = 127.0.0.1/8 192.168.1.1 # Local and trusted IPsEnable SSH protection ๐
[sshd]
enabled = true # Protect SSH logins
port = ssh
logpath = /var/log/auth.logStep 4: Start Fail2ban ๐ฆ
After configuring, start the Fail2ban service.
sudo systemctl start fail2banStep 5: Check Fail2ban status ๐
Ensure Fail2ban is running and protecting your server.
sudo fail2ban-client status๐ Youโre Done!
Fail2ban is now actively protecting your server from brute-force attacks. ๐