nftables
12 commands
12 shown
Create input chain with drop policy
Base-chain default-deny; note: add accept rules first or you lock yourself out
nft add chain inet filter input '{ type filter hook input priority 0 ; policy drop ; }'
Named set as IP blocklist
Reusable named set; flags interval lets you store CIDR ranges, not just hosts
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 }'
Verdict map for port dispatch
vmap maps keys to verdicts in O(1); replaces a chain of dport == rules
nft add rule inet filter input tcp dport vmap '{ 22 : accept, 80 : accept, 443 : accept, 3306 : drop }'
List ruleset with rule handles
-a prints '# handle N' per rule; you need the handle to delete a single rule
nft -a list ruleset
Delete a single rule by handle
Surgical removal without flushing; get the handle from nft -a list ruleset
nft delete rule inet filter input handle 7
Named counter on a rule
Inline counter tracks packets/bytes; reset with nft reset counters inet filter
nft add rule inet filter input tcp dport 22 counter accept comment \"ssh\"
SNAT masquerade for outbound NAT
Source-NAT egress to the iface IP; needs a nat-type postrouting chain to exist
nft add rule ip nat postrouting oifname \"eth0\" masquerade
DNAT port forward to internal host
Destination-NAT inbound to a backend; pair with a forward-chain accept rule
nft add rule ip nat prerouting iif \"eth0\" tcp dport 443 dnat to 10.0.0.5:8443
Rate-limit new connections
Throttle SSH brute-force; over-limit packets fall through to the chain policy
nft add rule inet filter input tcp dport 22 ct state new limit rate 10/minute accept
Watch ruleset changes live
Streams add/delete events as they happen; great for debugging dynamic rules
nft monitor ruleset
Atomic backup and restore of ruleset
nft -f applies the whole file atomically; partial failure rolls back, no half state
nft list ruleset > /etc/nftables.conf && nft -f /etc/nftables.conf
Hardware flowtable offload
Offloads established flows to fast path; add 'flags offload' for NIC hardware offload
nft add flowtable inet filter ft '{ hook ingress priority 0 ; devices = { eth0, eth1 } ; }' && nft add rule inet filter forward ct state established flow add @ft
no commands match