Back up and restore the ruleset atomically
nft -f applies the whole file atomically. If something fails, nothing is applied, so there is no half-applied state
nft list ruleset > /etc/nftables.conf && nft -f /etc/nftables.conf
- tool
- nftables12 commands
More nftables commands
-
nft add flowtable inet filter ft '{ hook ingress priority 0 ; devices = { eth0, eth1 } ; }' && nft add rule inet filter forward ct state established flow add @ftMoves established flows to the fast path. Add flags offload for hardware offload on the NIC
-
nft add chain inet filter input '{ type filter hook input priority 0 ; policy drop ; }'Base chain that denies everything by default. Note: add accept rules first, or you will lock yourself out
-
nft add set inet filter blocklist '{ type ipv4_addr ; flags interval ; }' && nft add element inet filter blocklist '{ 10.0.0.0/8, 192.0.2.5 }'A named set you can reuse in many rules. flags interval lets you store CIDR ranges, not only single hosts
-
nft add rule inet filter input tcp dport vmap '{ 22 : accept, 80 : accept, 443 : accept, 3306 : drop }'vmap maps keys to verdicts in O(1). It replaces a long chain of dport == rules
-
nft -a list ruleset-a prints # handle N for each rule. You need the handle to delete a single rule