Pcornel
Linux · Linux Firewall

iptables

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

Back to the Topic

Answer

iptables is the classic tool for netfilter rules, with tables (filter, nat, mangle) and chains (INPUT, FORWARD, OUTPUT …). On current distributions iptables is usually iptables-nft, which writes nftables rules.

Remember

Rules are evaluated top to bottom; the first terminating match wins. iptables -L -n -v --line-numbers shows counters. Save and restore with iptables-save/iptables-restore (or the distribution's persistence package). Do not mix iptables-legacy and nft rules.

First checks

  • 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

iptables -V
Fast checks
iptables

Verify in this order

packet → table and chain → rules top to bottom → first match target → policy if none

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

Confirmation

Confirm action

Continue?