Brute Force Protection with Fail2Ban
Fail2Ban monitors failed login attempts and automatically blocks IP addresses after a certain number of failed attempts.
Installation
apt update
apt install -y fail2ban
Configuration
Customize the default configuration by copying it (do not change the original):
cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
nano /etc/fail2ban/jail.local
Basic Settings
Find and edit the [DEFAULT] section:
[DEFAULT]
# Engelleme süresi (saniye) — 1 saat
bantime = 3600
# Bu süre içinde (saniye) — 10 dakika
findtime = 600
# Kaç başarısız denemede engellensin
maxretry = 5
# Kendi IP'nizi listeden çıkarın
ignoreip = 127.0.0.1/8 ::1 SİZİN_IP_ADRESİNİZ
SSH Protection
[sshd]
enabled = true
port = ssh
logpath = %(sshd_log)s
backend = %(sshd_backend)s
maxretry = 3
bantime = 86400
Starting the Service
systemctl enable fail2ban
systemctl start fail2ban
systemctl status fail2ban
Management Commands
# Engellenen IP'leri listele
fail2ban-client status sshd
# Belirli bir IP'yi engelle
fail2ban-client set sshd banip 1.2.3.4
# Belirli bir IP'nin engelini kaldır
fail2ban-client set sshd unbanip 1.2.3.4
# Tüm istatistikleri göster
fail2ban-client status
Log Monitoring
tail -f /var/log/fail2ban.log
info
Fail2Ban, sadece SSH değil; Apache, Nginx, Postfix gibi servisler için de yapılandırılabilir. Her servis için ayrı bir [jail] tanımı oluşturabilirsiniz.

