nftables – moderne Linux Firewall konfigurieren 2025

Nachfolger von iptables mit übersichtlicher Syntax

S
SeeColors IT
11. Juni 20264 Min. Lesezeit54 Aufrufe

iptables vs. nftables

iptables → veraltet, aber noch weit verbreitet
nftables → Standard ab Kernel 3.13, Ubuntu 21.04+, Debian 10+

Hauptvorteile von nftables:
+ Einheitliche Syntax für IPv4 und IPv6
+ Native Sets und Maps (IP-Listen ohne ipset)
+ Bessere Performance
+ Atomares Regelwerk-Update

nftables installieren und starten

apt install -y nftables
systemctl enable --now nftables

# Status
nft list ruleset

# UFW und iptables-Regeln sichern/löschen
ufw disable
iptables -F

Basis-Konfiguration (Server)

# /etc/nftables.conf
cat > /etc/nftables.conf << 'EOF'
#!/usr/sbin/nft -f
flush ruleset

table inet filter {

    # Erlaubte TCP-Ports
    set allowed_tcp {
        type inet_service
        elements = { 22, 80, 443, 2222 }
    }

    # Gebannte IPs (dynamisch befüllt)
    set banned_ips {
        type ipv4_addr
        flags dynamic, timeout
        timeout 1h
    }

    chain input {
        type filter hook input priority 0; policy drop;

        # Loopback immer erlauben
        iifname "lo" accept

        # Etablierte Verbindungen
        ct state established,related accept

        # ICMP Ping
        ip protocol icmp accept
        ip6 nexthdr icmpv6 accept

        # Gebannte IPs sofort verwerfen
        ip saddr @banned_ips drop

        # Erlaubte TCP-Ports
        tcp dport @allowed_tcp ct state new accept

        # Rest loggen und droppen
        limit rate 3/minute log prefix "nftables-drop: "
    }

    chain forward {
        type filter hook forward priority 0; policy drop;
    }

    chain output {
        type filter hook output priority 0; policy accept;
    }
}
EOF

nft -f /etc/nftables.conf
nft list ruleset

Rate Limiting und Brute-Force-Schutz

cat > /etc/nftables.conf << 'EOF'
#!/usr/sbin/nft -f
flush ruleset

table inet filter {

    # SSH Brute-Force-Schutz
    chain input {
        type filter hook input priority 0; policy drop;

        iifname "lo" accept
        ct state established,related accept
        ip protocol icmp accept

        # SSH Rate Limiting: max 3 neue Verbindungen/Minute
        tcp dport 22 ct state new             limit rate 3/minute             accept

        tcp dport 22 ct state new             log prefix "SSH-Brute-Force: "             drop

        tcp dport { 80, 443 } ct state new accept
    }
}
EOF

Dynamische Blockliste (mit IP-Sets)

# IP manuell sperren
nft add element inet filter banned_ips { 1.2.3.4 }

# IP entsperren
nft delete element inet filter banned_ips { 1.2.3.4 }

# Alle gebannten IPs
nft list set inet filter banned_ips

# Blockliste aus Datei laden (z.B. Spoofer-IPs)
for ip in $(cat /opt/blocklist.txt); do
    nft add element inet filter banned_ips { $ip }
done

NAT / Masquerading

cat >> /etc/nftables.conf << 'EOF'

table ip nat {
    chain postrouting {
        type nat hook postrouting priority 100;
        oifname "eth0" masquerade
    }
}
EOF

sysctl -w net.ipv4.ip_forward=1
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
nft -f /etc/nftables.conf

FAQ

Kann ich nftables und UFW gleichzeitig nutzen?
Nicht empfohlen. UFW nutzt iptables, nftables ist der Nachfolger. Entweder UFW (einfacher) oder nftables (mächtiger) verwenden.

Fazit

nftables bietet mächtigere und übersichtlichere Firewall-Regeln als iptables mit nativen IP-Sets und atomaren Regelwerk-Updates.

Linux-Firewall-Konfiguration für KMU in Heidelberg, Mannheim und der Rhein-Neckar-Region. Anfragen.

Artikel teilen

War dieser Artikel hilfreich?

Dein Feedback hilft uns, bessere Inhalte zu erstellen.

Kommentar hinterlassen

Verwandte Artikel