iptables vs nftables: Vergleich und Migrationsanleitung
Umfassender Vergleich von iptables und nftables, nftables-Syntax, Migrationsanleitung, häufige Regeläquivalente und wann welches Firewall-Tool verwendet werden sollte.
Inhaltsverzeichnis
iptables vs nftables: Vergleich und Migrationsanleitung
Jahrelang war iptables das Standard-Tool für Paketfilterung unter Linux. nftables ist jedoch seit 2014 im Linux-Kernel enthalten und ersetzt iptables in modernen Distributionen. Diese Anleitung vergleicht beide Tools, erklärt die nftables-Syntax und führt Sie durch die Migration.
Vergleichstabelle
| Merkmal | iptables | nftables |
|---|---|---|
| Erste Version | 1998 | 2014 |
| Syntax | Komplex, inkonsistent | Konsistent, lesbar |
| IPv4/IPv6 | Separate Tools | Einzelnes Tool |
| Leistung | Regelweise Auswertung | Optimiert |
| Atomare Updates | Nein | Ja |
| Standard (Ubuntu 20.04+) | Nein | Ja |
| Standard (Debian 10+) | Nein | Ja |
iptables Grundkonzepte
# Aktuelle iptables-Regeln anzeigen
sudo iptables -L -n -v
sudo iptables -L -n -v --line-numbers
# Grundlegende Regeln
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT
sudo iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
sudo iptables -P INPUT DROP
# Regeln speichern
sudo iptables-save > /etc/iptables/rules.v4
nftables Grundkonzepte
In nftables ist die Struktur: Tabelle → Kette → Regel
# nftables installieren
sudo apt install nftables -y
sudo systemctl enable nftables
sudo systemctl start nftables
# Aktuelle Regeln anzeigen
sudo nft list ruleset
nftables Konfigurationsdatei
sudo nano /etc/nftables.conf
#!/usr/sbin/nft -f
# Bestehende Regeln löschen
flush ruleset
# inet-Familie deckt IPv4 und IPv6 ab
table inet filter {
chain input {
type filter hook input priority 0; policy drop;
# Loopback-Schnittstelle erlauben
iif lo accept
# Bestehende Verbindungen erlauben
ct state established,related accept
# ICMP (Ping)
ip protocol icmp accept
ip6 nexthdr icmpv6 accept
# SSH
tcp dport 22 accept
# HTTP/HTTPS
tcp dport { 80, 443 } accept
# Protokollieren und ablehnen
log prefix "nftables-drop: " drop
}
chain forward {
type filter hook forward priority 0; policy drop;
}
chain output {
type filter hook output priority 0; policy accept;
}
}
# Konfiguration anwenden
sudo nft -f /etc/nftables.conf
# Syntax prüfen (ohne Anwenden)
sudo nft -c -f /etc/nftables.conf
Regeläquivalente
NAT-Regeln
# iptables NAT
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 192.168.1.10:80
# nftables NAT-Äquivalent
table ip nat {
chain prerouting {
type nat hook prerouting priority -100;
tcp dport 80 dnat to 192.168.1.10:80
tcp dport 443 dnat to 192.168.1.10:443
}
chain postrouting {
type nat hook postrouting priority 100;
oif eth0 masquerade
}
}
Rate Limiting
# nftables Rate Limiting
chain input {
tcp dport 22 limit rate 3/minute burst 5 packets accept
tcp dport 22 drop
}
IP-Sets
# nftables Sets (eingebaut)
table inet filter {
set blocked_ips {
type ipv4_addr
elements = { 1.2.3.4, 5.6.7.8 }
}
chain input {
type filter hook input priority 0; policy drop;
ip saddr @blocked_ips drop
tcp dport 22 accept
}
}
Migration von iptables zu nftables
Automatische Konvertierung
# Konvertierungstool installieren
sudo apt install iptables-nftables-compat -y
# Bestehende iptables-Regeln konvertieren
iptables-save | iptables-restore-translate -f /etc/nftables.conf
ip6tables-save | ip6tables-restore-translate >> /etc/nftables.conf
Manuelle Migrationsschritte
# 1. Bestehende iptables-Regeln sichern
sudo iptables-save > /root/iptables-backup.txt
# 2. nftables-Konfiguration erstellen
sudo nano /etc/nftables.conf
# 3. Konfiguration testen
sudo nft -c -f /etc/nftables.conf
# 4. nftables aktivieren
sudo systemctl enable nftables
sudo nft -f /etc/nftables.conf
# 5. iptables deaktivieren
sudo systemctl disable iptables
sudo systemctl stop iptables
# 6. Regeln überprüfen
sudo nft list ruleset
Wann welches verwenden?
iptables verwenden:
- Legacy-Systeme (CentOS 7, Ubuntu 18.04)
- Bestehende iptables-Skripte vorhanden
- Team ist mit iptables vertraut
nftables verwenden:
- Neue Installationen (Ubuntu 20.04+, Debian 10+)
- IPv4 und IPv6 gemeinsam verwalten
- Sauberere Syntax gewünscht
- Atomare Regelaktualisierungen erforderlich
Seit Ubuntu 20.04 und Debian 10 führt der Befehl iptables tatsächlich den iptables-nft-Wrapper aus — er verwendet also nftables im Hintergrund. Verwenden Sie iptables-legacy für echtes iptables.
Fazit
nftables ersetzt iptables in modernen Linux-Systemen. Es bietet konsistentere Syntax, einheitliche IPv4/IPv6-Verwaltung und bessere Leistung. Wählen Sie nftables für neue Installationen; planen Sie eine Migration für bestehende iptables-Infrastruktur.
Verwandte Artikel
Malware & Rootkit-Scan: rkhunter und ClamAV Anleitung
Schützen Sie Ihren Linux-Server vor Malware und Rootkits. rkhunter und ClamAV Installation, Scan-Konfiguration, Ergebnisinterpretation, geplante Scans und Incident-Response-Anleitung.
Fail2Ban Konfiguration: SSH Brute-Force-Schutz Anleitung
Schützen Sie Ihren Server vor SSH-Brute-Force-Angriffen mit Fail2Ban. Installation, jail.local-Konfiguration, Nginx/Apache-Jails, IP-Whitelist, Ban-Überwachung und E-Mail-Benachrichtigungen.
WireGuard VPN-Server einrichten: Schritt-für-Schritt-Anleitung
WireGuard VPN-Server einrichten: Schlüsselgenerierung, Server- und Client-Konfiguration, IP-Weiterleitung, Firewall-Regeln und Windows/Linux/Android-Client-Setup.