What does the iptables chain order look like for a packet?
IntermediateConceptNAT, Firewalls & VPN
Answer
Incoming packets hit PREROUTING (raw, mangle, nat), then a routing decision: local delivery goes through INPUT, forwarded packets go through FORWARD, then POSTROUTING. Locally generated packets go OUTPUT then POSTROUTING. Within each hook, tables are evaluated in a fixed order (raw, conntrack, mangle, nat, filter).
DNAT happens in PREROUTING before routing, SNAT/MASQUERADE in POSTROUTING after. nftables replaces iptables in modern distros with the same hook model.
More on NAT, Firewalls & VPN
What is NAT and why is it used?BeginnerWhat is the difference between SNAT, DNAT and PAT?AdvancedHow does an AWS NAT gateway work, and what are its limits?AdvancedWhy is NAT gateway cost a common surprise and how do you reduce it?IntermediateWhat is conntrack and what happens when its table fills up?AdvancedWhat is the difference between a stateful and a stateless firewall?Beginner