iptables
, ip6tables
, arptables
und ebtables
gesteuert werden kann.
nft
verwendet werden. Debian Buster verwendet standardmäßig das nftables-Framework.
#
apt install -y nftables
Reading package lists... Done ... #
systemctl enable nftables.service
Created symlink /etc/systemd/system/sysinit.target.wants/nftables.service → /lib/systemd/system/nftables.service.
ip
, ip6
, inet
, arp
oder bridge
. Ist die Kategorie nicht deklariert, wird ip
genutzt.
accept
, drop
, queue
, continue
, return
, jump chain
oder goto chain
.
iptables-translate
und ip6tables-translate
können dazu genutzt werden, iptables Befehle in die neuen nftables Syntax zu konvertieren. In einem Rechner mit installiertem Docker können sogar komplette Regelsätze (rulesets) konvertiert werden:
#
iptables-save > iptables-ruleset.txt
#
iptables-restore-translate -f iptables-ruleset.txt
# Translated by iptables-restore-translate v1.8.2 on Thu Jul 18 10:39:33 2019 add table ip filter add chain ip filter INPUT { type filter hook input priority 0; policy accept; } add chain ip filter FORWARD { type filter hook forward priority 0; policy drop; } add chain ip filter OUTPUT { type filter hook output priority 0; policy accept; } add chain ip filter DOCKER add chain ip filter DOCKER-ISOLATION-STAGE-1 add chain ip filter DOCKER-ISOLATION-STAGE-2 add chain ip filter DOCKER-USER add rule ip filter FORWARD counter jump DOCKER-USER add rule ip filter FORWARD counter jump DOCKER-ISOLATION-STAGE-1 add rule ip filter FORWARD oifname "docker0" ct state related,established counter accept add rule ip filter FORWARD oifname "docker0" counter jump DOCKER add rule ip filter FORWARD iifname "docker0" oifname != "docker0" counter accept add rule ip filter FORWARD iifname "docker0" oifname "docker0" counter accept add rule ip filter DOCKER-ISOLATION-STAGE-1 iifname "docker0" oifname != "docker0" counter jump DOCKER-ISOLATION-STAGE-2 add rule ip filter DOCKER-ISOLATION-STAGE-1 counter return add rule ip filter DOCKER-ISOLATION-STAGE-2 oifname "docker0" counter drop add rule ip filter DOCKER-ISOLATION-STAGE-2 counter return add rule ip filter DOCKER-USER counter return add table ip nat add chain ip nat PREROUTING { type nat hook prerouting priority -100; policy accept; } add chain ip nat INPUT { type nat hook input priority 100; policy accept; } add chain ip nat POSTROUTING { type nat hook postrouting priority 100; policy accept; } add chain ip nat OUTPUT { type nat hook output priority -100; policy accept; } add chain ip nat DOCKER add rule ip nat PREROUTING fib daddr type local counter jump DOCKER add rule ip nat POSTROUTING oifname != "docker0" ip saddr 172.17.0.0/16 counter masquerade add rule ip nat OUTPUT ip daddr != 127.0.0.0/8 fib daddr type local counter jump DOCKER add rule ip nat DOCKER iifname "docker0" counter return # Completed on Thu Jul 18 10:39:33 2019 #
iptables-restore-translate -f iptables-ruleset.txt > ruleset.nft
#
nft -f ruleset.nft
#
nft list ruleset
table ip filter { chain INPUT { type filter hook input priority 0; policy accept; } chain FORWARD { type filter hook forward priority 0; policy drop; counter packets 0 bytes 0 jump DOCKER-USER counter packets 0 bytes 0 jump DOCKER-ISOLATION-STAGE-1 oifname "docker0" ct state related,established counter packets 0 bytes 0 accept oifname "docker0" counter packets 0 bytes 0 jump DOCKER iifname "docker0" oifname != "docker0" counter packets 0 bytes 0 accept iifname "docker0" oifname "docker0" counter packets 0 bytes 0 accept } chain OUTPUT { type filter hook output priority 0; policy accept; } chain DOCKER { } chain DOCKER-ISOLATION-STAGE-1 { iifname "docker0" oifname != "docker0" counter packets 0 bytes 0 jump DOCKER-ISOLATION-STAGE-2 counter packets 0 bytes 0 return } chain DOCKER-ISOLATION-STAGE-2 { oifname "docker0" counter packets 0 bytes 0 drop counter packets 0 bytes 0 return } chain DOCKER-USER { counter packets 0 bytes 0 return } } table ip nat { chain PREROUTING { type nat hook prerouting priority -100; policy accept; fib daddr type local counter packets 0 bytes 0 jump DOCKER } chain INPUT { type nat hook input priority 100; policy accept; } chain POSTROUTING { type nat hook postrouting priority 100; policy accept; oifname != "docker0" ip saddr 172.17.0.0/16 counter packets 0 bytes 0 masquerade } chain OUTPUT { type nat hook output priority -100; policy accept; ip daddr != 127.0.0.0/8 fib daddr type local counter packets 0 bytes 0 jump DOCKER } chain DOCKER { iifname "docker0" counter packets 0 bytes 0 return } } table ip mangle { chain PREROUTING { type filter hook prerouting priority -150; policy accept; } chain INPUT { type filter hook input priority -150; policy accept; } chain FORWARD { type filter hook forward priority -150; policy accept; } chain OUTPUT { type route hook output priority -150; policy accept; } chain POSTROUTING { type filter hook postrouting priority -150; policy accept; } }
iptables-nft
, ip6tables-nft
, arptables-nft
, ebtables-nft
sind Versionen von iptables welche die nftables API nutzen, damit Systemverwalter die veraltete iptables-Syntax weiter nutzen können. Aber dies wird nicht empfohlen; stattdessen sollten diese Hilfsprogramme lediglich die Rückwärtskompatibilität ermöglichen.
nft
erlaubt die Bearbeitung von Tabellen (tables), Ketten (chains) und Regeln (rules). Die Tabellen-
-Option bietet mehrere Optionen: add
, create
, delete
, list
und flush
. nft add table ip6 mangle
erstellt eine neue Tabelle aus der Protokloll-Familie ip6
.
filter
-Tabelle zu erstellen, wird das folgende Kommando ausgeführt (Beachten Sie, dass das Semikolon bei Verwendung von Bash mit einem Backslash versehen werden muss):
#
nft add chain filter input { type filter hook input priority 0 \; }
nft add rule [Familie] Tabelle Kette handle Handle statement
.
insert
ähnelt dem Befehl add
, aber die angegebene Regel wird am Anfang der Kette oder vor der Regel mit dem angegebenen Handle vorangestellt, anstatt am Ende oder nach dieser Regel. Beispielsweise fügt der folgende Befehl eine Regel vor der Regel mit dem Handler Nummer 8 ein:
#
nft insert rule filter output position 8 ip daddr 127.0.0.8 drop
nft
-Befehle nehmen keine dauerhaften Änderungen an der Konfiguration vor, sodass sie verloren gehen, wenn sie nicht gespeichert werden. Die Firewall-Regeln befinden sich in /etc/nftables.conf
. Eine einfache Möglichkeit, die aktuelle Firewall-Konfiguration dauerhaft zu speichern, besteht darin, nft list ruleset > /etc/nftables.conf
als root auszuführen.
nft
erlaubt viele weitere Operationen, siehe seine Handbuchseite nft(8) für weitere Informationen.
/etc/nftables.conf
speichern und systemctl enable nftables.service
als root ausführen. Sie können die Firewall daran hindern, nft flush ruleset
als root auszuführen.
up
-Anweisung der Datei /etc/network/interfaces
einzutragen. Im folgenden Beispiel ist das Skript unter /usr/local/etc/arrakis.fw
gespeichert.
Beispiel 14.1. Aufruf eines Firewallskripts durch eine interfaces
-Datei
auto eth0 iface eth0 inet static address 192.168.0.1 network 192.168.0.0 netmask 255.255.255.0 broadcast 192.168.0.255 up /usr/local/etc/arrakis.fw