All Guides

Установка Fail2Ban

Защитите сервер от brute-force атак.

Intermediate15 мин.

Setup Steps

1. Install Fail2Ban:

sudo apt install fail2ban -y

2. Create configuration file:

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

3. Basic settings:

[DEFAULT]
bantime = 3600
findtime = 600
maxretry = 5

[sshd]
enabled = true
port = ssh
logpath = %(sshd_log)s
maxretry = 3

4. Apache protection:

[apache-auth]
enabled = true
port = http,https
logpath = %(apache_error_log)s
maxretry = 5

5. Nginx protection:

[nginx-http-auth]
enabled = true
port = http,https
logpath = /var/log/nginx/error.log

6. Start the service:

sudo systemctl start fail2ban
sudo systemctl enable fail2ban

7. Check status:

sudo fail2ban-client status
sudo fail2ban-client status sshd

8. Unban an IP:

sudo fail2ban-client set sshd unbanip 192.168.1.100