DDoS Schutz Strategien Linux Server
DDoS-Schutz Strategien für Linux-Server – Anleitung
Arten von DDoS-Angriffen
Volumetric Attacks (Volumen-Attacken)
Ziel: Bandbreite überlasten. Der Angreifer sendet massive Mengen an Daten zum Ziel.
- UDP Flood: Viele UDP-Pakete auf verschiedene Ports
- DNS Amplification: DNS-Queries verstärken sich auf Zielserver
- ICMP Flood: Ping-Attacke mit großen Paketen
Protocol Attacks (Protokoll-Attacken)
Ziel: Ressourcen des Servers oder der Infrastruktur aufbrauchen.
- SYN Flood: Viele TCP SYN-Requests ohne Completion
- Fragmented Packet Attacks: Fragmentierte Pakete, die Re-Assembly überlasten
- Ping of Death: Oversized ICMP-Pakete
Application Layer Attacks (Anwendungsebenen-Attacken)
Ziel: Legitime Anfragen zu senden, aber massiv. Der Server antwortet, wird aber überlastet.
- HTTP Flood: Viele legitime HTTP-Requests (GET/POST)
- Slowloris: Langsame Requests, die Connections offen halten
- Cache Busting: Requests mit unterschiedlichen Query-Parametern
DDoS Detection – Netzwerk-Aktivität überwachen
Mit netstat aktive Verbindungen prüfen
$ netstat -an | grep ESTABLISHED | wc -l 1234
Sehe Verbindungen nach IP gruppiert:
$ netstat -an | grep ESTABLISHED | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -rn | head -10
145 192.168.1.50
98 10.0.0.200
45 203.0.113.5
Mit ss (schneller Ersatz für netstat)
$ ss -an | grep ESTABLISHED | wc -l # Connections nach State $ ss -an | grep SYN_RECV | wc -l # SYN Flood Anzeichen $ ss -an | grep TIME_WAIT | wc -l
Mit iftop Bandbreite pro IP überwachen
$ sudo iftop -n -P -B 192.168.1.50 => 10.20.30.40 100 Mbps 10.0.0.200 => 10.20.30.40 50 Mbps 203.0.113.5 => 10.20.30.40 25 Mbps
Mit nethogs Prozess-Bandbreite anzeigen
$ sudo nethogs eth0 PID USER PROGRAM DEV SENT RECV 1234 www-data /usr/sbin/nginx eth0 100 Mbps 200 Mbps 5678 mysql /usr/sbin/mysqld eth0 50 Mbps 75 Mbps
Rate Limiting mit iptables
SYN Flood-Schutz mit hashlimit
Limitiere eingehende Connections pro IP auf maximal 10 pro Minute:
$ sudo iptables -A INPUT -p tcp --dport 80 -m hashlimit \ --hashlimit-name http-limit \ --hashlimit 10/minute \ --hashlimit-burst 20 \ -j ACCEPT $ sudo iptables -A INPUT -p tcp --dport 80 -j DROP
Erklärt:
--hashlimit-name:Name der Limit-Tabelle--hashlimit 10/minute:Maximal 10 Requests pro Minute und IP--hashlimit-burst 20:Kurzzeitig bis zu 20 erlaubt
UDP Flood-Schutz
$ sudo iptables -A INPUT -p udp -m limit --limit 10/s --limit-burst 20 -j ACCEPT $ sudo iptables -A INPUT -p udp -j DROP
Schutz vor Port Scanning
$ sudo iptables -N port-scanning $ sudo iptables -A port-scanning -p tcp --tcp-flags SYN,ACK,FIN,RST RST \ -m limit --limit 1/s --limit-burst 2 -j RETURN $ sudo iptables -A port-scanning -j DROP
UFW Rate Limiting
Mit UFW ist Rate Limiting noch einfacher:
$ sudo ufw limit 22/tcp # SSH: max 6 connections pro 30s pro IP $ sudo ufw limit 80/tcp # HTTP: max 6 connections pro 30s pro IP $ sudo ufw limit 443/tcp # HTTPS
Aktuelle Regeln anzeigen:
$ sudo ufw status numbered
To Action From
-- ------ ----
[ 1] 22/tcp LIMIT Anywhere
[ 2] 80/tcp LIMIT Anywhere
[ 3] 443/tcp LIMIT Anywhere
Nginx Rate Limiting
Request-Rate begrenzen
Editiere die Nginx-Konfiguration:
$ sudo nano /etc/nginx/nginx.conf
Füge diese Zeilen im http-Block ein:
http {
limit_req_zone $binary_remote_addr zone=http_limit:10m rate=10r/s;
limit_req_zone $binary_remote_addr zone=api_limit:10m rate=30r/m;
server {
listen 80;
server_name example.com;
location / {
limit_req zone=http_limit burst=20 nodelay;
proxy_pass http://backend;
}
location /api/ {
limit_req zone=api_limit burst=5 nodelay;
proxy_pass http://api_backend;
}
}
}
Erklärt:
limit_req_zone:Definiert eine Zone mit Limit$binary_remote_addr:Limitiere pro Client-IPrate=10r/s:10 Requests pro Sekundeburst=20:Bis zu 20 Requests im Puffer erlaubtnodelay:Verarbeite gepufferte Requests sofort
Nginx testen und neu laden
$ sudo nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok $ sudo systemctl reload nginx
Kernel Hardening gegen SYN Floods
TCP SYN Cookies aktivieren
Editiere /etc/sysctl.conf:
$ sudo nano /etc/sysctl.conf
Füge diese Zeilen am Ende hinzu:
# SYN Flood Protection net.ipv4.tcp_syncookies = 1 net.ipv4.tcp_syn_retries = 2 net.ipv4.tcp_synack_retries = 2 net.ipv4.tcp_max_syn_backlog = 4096 # Weitere Kernel-Hardening-Optionen net.ipv4.conf.all.rp_filter = 1 net.ipv4.conf.default.rp_filter = 1 net.ipv4.icmp_echo_ignore_broadcasts = 1 net.ipv4.icmp_ignore_bogus_error_responses = 1 net.ipv4.tcp_timestamps = 1
Einstellungen laden
$ sudo sysctl -p
Aktuelle Werte überprüfen:
$ sysctl net.ipv4.tcp_syncookies net.ipv4.tcp_syncookies = 1
Cloudflare als CDN-Schutz
Cloudflare bietet DDoS-Schutz auf CDN-Ebene:
- Aktiviere Cloudflare DDoS Protection in der Security-Sektion
- Wähle I'm Under Attack Mode für erhöhte Sicherheit
- Nutze Rate Limiting und WAF (Web Application Firewall)
- Konfiguriere Challenge Settings (CAPTCHA vor Bot-Traffic)
Fail2Ban für HTTP Flood-Schutz
Fail2Ban installieren
$ sudo apt install fail2ban
HTTP Flood-Filter erstellen
Editiere die Fail2Ban-Jail-Konfiguration:
$ sudo nano /etc/fail2ban/jail.d/http-flood.conf
Füge hinzu:
[Definition]
[http-flood]
enabled = true
port = http,https
filter = http-flood
logpath = /var/log/apache2/access.log
maxretry = 100
findtime = 60
bantime = 3600
action = iptables-multiport[name=HTTP, port="http,https"]
sendmail-whois[name=HTTP]
Fail2Ban testen und starten
$ sudo fail2ban-client start $ sudo fail2ban-client status $ sudo systemctl enable fail2ban
Bandbreite mit vnstat überwachen
vnstat installieren
$ sudo apt install vnstat
Tägliche Statistiken anzeigen
$ vnstat -d
Database updated: 2026-03-05
eth0 daily statistics
day rx | tx | total | avg. rate
----- ----------- | ----------- | ----------- | -----------
2026-03-05 512 MiB | 234 MiB | 746 MiB | 23.4 Mbps
2026-03-04 623 MiB | 345 MiB | 968 MiB | 30.2 Mbps
Multi-Layer DDoS-Schutz Zusammenfassung
| Layer | Technik | Schutz vor |
|---|---|---|
| Kernel | sysctl.conf, TCP Syncookies | SYN Floods, ICMP Floods |
| Firewall | iptables, UFW Rate Limiting | Volumetric Attacks, Protocol Attacks |
| Webserver | Nginx Rate Limiting | HTTP Floods, Application Layer Attacks |
| Applikation | Fail2Ban, WAF | Slowloris, Cache Busting |
| CDN | Cloudflare, Akamai | Alle DDoS-Typen |