Fail2ban überwacht Logs und sperrt IPs vorübergehend bei Missbrauch (SSH-Bruteforce, HTTP-Scans). Ergänzt UFW und SSH-Härtung.
Voraussetzungen
- Ubuntu/Debian mit
sudo - Geschützter Dienst läuft (z. B.
sshd,nginx)
Installation
Bashsudo apt update && sudo apt install -y fail2ban sudo systemctl enable fail2ban sudo systemctl start fail2ban
Basis-Konfiguration
Eigene Dateien unter /etc/fail2ban/jail.d/, z. B. local.conf:
INI1[DEFAULT] 2bantime = 1h 3findtime = 10m 4maxretry = 5 5ignoreip = 127.0.0.1/8 ::1 6 7[sshd] 8enabled = true 9port = ssh 10logpath = %(sshd_log)s 11backend = %(sshd_backend)s
Bei geändertem SSH-Port: port = 2222 statt ssh.
Bashsudo systemctl restart fail2ban sudo fail2ban-client status sshd
Nginx (Beispiel)
INI[nginx-http-auth] enabled = true port = http,https logpath = /var/log/nginx/error.log
IP manuell entsperren
Bashsudo fail2ban-client set sshd unbanip 198.51.100.10
Fehlerbehebung
- Keine Bans:
enabled,logpath, Logging fehlgeschlagener Logins prüfen. - Aussperrung: Provider-Konsole oder zweite IP,
ignoreipanpassen.