iptables Process Flow: Chains, Tables, and Rules
20,146 Total views across this article’s versions; includes the historical baseline where available.
The terms table, chain, and hook describe different parts of packet filtering. A table contains chains, and each chain contains an ordered list of rules. Netfilter hooks are points in the kernel’s packet path. Built-in iptables chains are attached to those hooks; for example, mangle/OUTPUT and filter/OUTPUT are separate chains in separate tables at the OUTPUT hook.
When no -t option is supplied, iptables uses the filter table. Specify the table and chain explicitly when their distinction matters. A rule in filter/INPUT will not inspect ordinary forwarded traffic, which uses FORWARD instead. The available built-in chains differ by table; packets do not traverse all five tables and all five hooks.
| Traffic | Simplified IPv4 path |
|---|---|
| Arriving for this host | Network → PREROUTING → routing decision → INPUT → local process |
| Forwarded through this host | Network → PREROUTING → routing decision → FORWARD → POSTROUTING → network |
| Created by this host | Local process → initial route/source selection → OUTPUT → POSTROUTING → network |
These are simplified paths for ordinary IPv4 traffic. OUTPUT changes can trigger another routing lookup, and loopback can traverse both the output and input paths. See the routing overview.
The next table shows the usual relative order for iptables. An entry represents that table’s chain at the named hook; connection tracking is a separate kernel operation.
| Hook | Conventional iptables processing order |
|---|---|
| PREROUTING | raw → connection tracking → mangle → nat (destination translation) |
| INPUT | mangle → filter → security → nat (source translation) |
| FORWARD | mangle → filter → security |
| OUTPUT | raw → connection tracking → mangle → nat (destination translation) → filter → security |
| POSTROUTING | mangle → nat (source translation) |
The kernel assigns priorities to hook operations. Where needed, defragmentation normally precedes raw processing; the kernel also supports an earlier raw priority. Connection confirmation occurs late in INPUT and POSTROUTING, so it should not be confused with the earlier connection lookup in PREROUTING and OUTPUT. These are conventional iptables positions, not a requirement that native nftables chains use the same priorities. See the kernel priority definitions and connection-tracking hook registrations.
Rules in each chain run in their configured order. A matching rule’s target determines whether processing continues, jumps, returns, accepts, or drops. An ACCEPT verdict in one table does not bypass later hooks or prevent a later table from dropping the packet. For stateful NAT, the first packet establishes the translation binding; subsequent packets use that binding rather than evaluating all NAT rules again.
CONNTRACK
Connection tracking associates packets with a flow and records state that firewall rules can match. It is not a mark that leaves the host and comes back in a reply.
A packet mark is local kernel metadata. A connection mark is a separate value associated with a tracked connection. Saving and restoring marks requires explicit rules, such as the CONNMARK operations described in Helpful Tips. Neither value is transmitted as an IP header field.
conntrack vs. CONNTRACK Confusion
The kernel’s connection-tracking subsystem maintains connection state. The iptables -m conntrack match reads that state and related properties; it depends on tracking, rather than operating independently of it. The separate conntrack userspace utility can inspect and manage the connection-tracking table.
Uppercase “CONNTRACK” in a diagram usually labels the kernel processing stage. It is not an iptables target named CONNTRACK; the CT target configures tracking parameters, while CONNMARK manages connection marks.
Custom Chains
Create a custom chain in a particular table before adding rules to it. A jump or goto from a chain in the same table can reach it, including through another custom chain. A custom chain that is never reached from a relevant built-in chain will not inspect that traffic.
A jump made with -j can return to the next rule in its calling chain. Reaching the end of the custom chain acts as a return; an explicit final RETURN is optional. -g has different return behavior, so do not substitute it for -j without checking the intended flow. See How to Create Custom Chains.
Chain Policies
A built-in chain’s policy applies when processing reaches its end, or when RETURN is reached in that built-in chain. Earlier nonterminating actions, such as logging or marking, do not prevent the policy from applying.
The policy can be ACCEPT or DROP. REJECT is a rule target, not a chain policy. Custom chains do not have policies.
References: iptables manual, iptables extensions, and Netfilter NAT overview.