Pcornel
Linux · Linux Firewall

nftables

Cheat sheet · https://pcornel.dk/topic.php?topic=367

Back to the Topic

Answer

nftables is the Linux packet filter. Rules sit in chains inside tables; a base chain is attached to a point in the packet's path (input, forward, output), and each packet is checked against the rules in order.

Remember

Read the whole ruleset: firewalld, Docker and the iptables compatibility layer create tables of their own, and a drop in any chain on the hook is final. Traffic to the host uses input; traffic through it uses forward. Rules added on the command line are gone after a reboot.

First checks

  • nft list ruleset — everything in force, whoever wrote it.
  • nft -a list chain inet filter input — one chain with rule handles.
  • nft -c -f /etc/nftables.conf — check a file without applying it.
  • nft monitor trace — follow a packet marked with meta nftrace set 1.
  • ss -ltn — is the service listening at all?

Commands

nft list ruleset
Fast checks
nft monitor trace
Fast checks
nft -f file
nft -c -f
nft -f <file>
nft -c -f <file>
iptables -L
nft add rule
ss -ltn

Verify in this order

packet arrives → every base chain on the hook, in priority order → rules top down, first verdict wins → no drop in any chain → accepted → service listening → reply passes as established

Where it usually breaks

First mismatch in link/interface → address/namespace → route/neighbor → firewall/policy → socket/daemon → DNS/TLS/SSH/application peer path; preserve identity/native diagnostic/pre-state before mutation.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=367

Confirmation

Confirm action

Continue?