Skip to content

Instantly share code, notes, and snippets.

@steffen-wirth
Last active September 22, 2025 07:07
Show Gist options
  • Select an option

  • Save steffen-wirth/d4d31c54293a0bc713a1c89764071f1e to your computer and use it in GitHub Desktop.

Select an option

Save steffen-wirth/d4d31c54293a0bc713a1c89764071f1e to your computer and use it in GitHub Desktop.
Fail2Ban
```
sudo apt update;
sudo apt install fail2ban;
sudo nano /etc/fail2ban/jail.local;
```
#
Grundkonfiguration:
```[DEFAULT]
bantime = 1h
findtime = 10m
maxretry = 50
backend = systemd
ignoreip = 127.0.0.1/8 ::1
#Das blockt IPs, die mehr als 100 Requests pro Minute senden.
[apache-req-limit]
enabled = true
port = http,https
filter = apache-req-limit
logpath = /var/log/apache2/access.log
maxretry = 100
findtime = 60
bantime = 10m
```
#
Dann das Filter-File erstellen
`sudo nano /etc/fail2ban/filter.d/apache-req-limit.conf
`
```
[Definition]
failregex = ^<HOST> -.*"(GET|POST).*
```
```
sudo systemctl restart fail2ban
sudo fail2ban-client status
```
#
🔑 2. mod_evasive (direkt in Apache)
Wenn du Apache nutzt, kannst du mod_evasive installieren – das blockiert IPs sofort, wenn sie zu viele Requests in kurzer Zeit schicken.
```
sudo apt install libapache2-mod-evasive
sudo mkdir /var/log/mod_evasive
sudo chown www-data:www-data /var/log/mod_evasive
```
Konfiguration:
`sudo nano /etc/apache2/mods-available/evasive.conf`
Beispiel:
```
<IfModule mod_evasive20.c>
DOSHashTableSize 3097
DOSPageCount 5
DOSSiteCount 50
DOSPageInterval 1
DOSSiteInterval 1
DOSBlockingPeriod 600
DOSEmailNotify you@example.com
DOSLogDir "/var/log/mod_evasive"
</IfModule>
```
Danach:
```
sudo a2enmod evasive
sudo systemctl restart apache2
```
Jetzt werden IPs für 10 Minuten blockiert, wenn sie mehr als 50 Requests pro Sekunde schicken.
🔑 3. Cloudflare / Reverse Proxy
Wenn du viele Angriffe aus dem Internet bekommst, kann es sich lohnen, deinen Server hinter Cloudflare oder einem anderen Reverse Proxy zu verstecken.
Cloudflare blockiert bekannte Botnetze und DDoS automatisch, bevor sie dich erreichen.
🔑 4. Netzwerkseitige Lösungen
Wenn es wirklich aggressiv wird:
iptables oder ufw Rate-Limits setzen
Tools wie crowdsec (modernere Alternative zu Fail2Ban, Community-geteilte IP-Blocklisten)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment