Pcornel
Linux · Linux Firewall

Netfilter

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

Back to the Topic

Answer

Netfilter is the kernel framework behind Linux firewalls and NAT. Packets pass hooks — prerouting, input, forward, output, postrouting — where tables and chains of rules act on them; conntrack tracks connection state.

Remember

Incoming traffic to the host hits INPUT; routed traffic hits FORWARD; NAT happens in PREROUTING (DNAT) and POSTROUTING (SNAT). Allow ESTABLISHED,RELATED early so replies pass. conntrack -L shows tracked connections.

First checks

  • conntrack -L — tracked connections
  • nft list ruleset — all nftables rules
  • iptables -S; iptables -t nat -S — iptables rules (if used)
  • firewall-cmd --list-all — firewalld zone settings
  • ufw status verbose — UFW rules and defaults
  • ss -tulpn — which services listen

Commands

nft list hooks

Verify in this order

prerouting (DNAT) → routing decision → input or forward → output → postrouting (SNAT)

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=2810

Confirmation

Confirm action

Continue?