Map ports to verdicts

vmap maps keys to verdicts in O(1). It replaces a long chain of dport == rules

nft add rule inet filter input tcp dport vmap '{ 22 : accept, 80 : accept, 443 : accept, 3306 : drop }'

tool
nftables12 commands
tags
nftablesnetworkperformancefirewall

More nftables commands

  • nft -a list ruleset

    -a prints # handle N for each rule. You need the handle to delete a single rule

  • nft delete rule inet filter input handle 7

    Remove one rule without flushing the chain. Get the handle from nft -a list ruleset

  • nft add rule inet filter input tcp dport 22 counter accept comment \"ssh\"

    The inline counter counts packets and bytes. Reset it with nft reset counters inet filter

  • nft add rule ip nat postrouting oifname \"eth0\" masquerade

    Source NAT for outgoing traffic to the interface IP. Needs an existing postrouting chain of type nat

  • nft add rule ip nat prerouting iif \"eth0\" tcp dport 443 dnat to 10.0.0.5:8443

    Destination NAT for incoming traffic to a backend. Add an accept rule in the forward chain too

all 12 nftables commands