Chart: iptables Command Matrix

Topics · Published 2019-08-27 · Revised 2026-11-23
Reviewed corrections applied locally; pre-review version preserved separately · Joomla source

3,389 Total views across this article’s versions; includes the historical baseline where available.

This matrix summarizes common IPv4 iptables matches and targets. Each syntax cell is a rule fragment, not a complete command. Add the table, chain operation, appropriate match restrictions, and target when assembling a rule.

The placement column gives compatible table/chain pairs or explicit restrictions. Example placements are not an exhaustive list of every supported hook. Kernel, backend, and extension availability still apply. In particular, separate table and chain names cannot be freely combined: filter/POSTROUTING does not exist.

Packet and connection matches

PurposeRule fragmentValid example placementQualification
Source port-p tcp --sport 1024:65535filter/INPUTTCP or UDP ordinary port/range matching; not ICMP.
Destination port-p udp --dport 53filter/OUTPUTOne port or colon-separated range.
Destination address interval-m iprange --dst-range 192.0.2.10-192.0.2.20filter/FORWARDAn address interval, not CIDR syntax.
Source address interval-m iprange --src-range 192.0.2.10-192.0.2.20filter/INPUTUse -s for a source CIDR prefix.
Source MAC address-m mac --mac-source 02:00:00:00:00:01filter/INPUT or filter/FORWARDAlso usable in PREROUTING where the table supports it. Requires a suitable received Ethernet frame.
Packet mark-m mark --mark 32mangle/PREROUTINGReads packet metadata; does not set it.
Destination port list-p tcp -m multiport --dports 80,443,8000:8005filter/INPUT15 slots maximum; a range counts as two.
Source port list-p udp -m multiport --sports 53,123filter/OUTPUTTCP, UDP, UDP-Lite, DCCP, or SCTP.
Socket group owner-m owner --gid-owner 1000-1005filter/OUTPUT or mangle/POSTROUTINGLocal originating socket; numeric ranges use a hyphen.
Socket user owner-m owner --uid-owner 1000filter/OUTPUT or mangle/POSTROUTINGNot a remote user identity or a forwarded-packet attribute.
Destination address/prefix-d 198.51.100.0/24filter/FORWARDAddress match; no transport protocol required.
Source address/prefix-s 192.0.2.0/24filter/INPUTAddress match; no transport protocol required.
Connection mark-m connmark --mark 32mangle/PREROUTINGReads the tracked connection mark, not the packet mark.
Connection state-m conntrack --ctstate ESTABLISHED,RELATEDfilter/INPUTThe option is --ctstate, with no hyphen between ct and state.

Targets and verdicts

User-defined chains retain the restrictions of the hooks that can reach them. The CONNMARK and MARK entries deliberately use mangle placements suitable for the examples; they do not assert that every backend supports only those combinations.

PurposeRule fragmentPlacementQualification
Restore connection mark to packet-j CONNMARK --restore-markmangle/PREROUTING or mangle/OUTPUTRequires a tracked connection. Position it before the routing decision that needs the mark.
Copy security label-j CONNSECMARK --save or -j CONNSECMARK --restoresecurity/INPUT, FORWARD, OUTPUT; mangle also supportedCopies only into an unlabeled connection or packet; separate from routing marks.
Destination NAT-j DNAT --to-destination 192.0.2.10:8080nat/PREROUTING or nat/OUTPUTThis port form requires TCP, UDP, DCCP, or SCTP. Does not itself allow delivery/forwarding.
Source NAT-j SNAT --to-source 198.51.100.10nat/POSTROUTING; nat/INPUT since Linux 2.6.36Adding :PORT changes the source port, not the destination port.
Set packet mark-j MARK --set-mark 32Use mangle/PREROUTING or mangle/OUTPUT for policy routing.Marks may serve other consumers at other hooks; INPUT is too late for the incoming routing decision.
Set security label-j SECMARK --selctx SECURITY_CONTEXTsecurity/INPUT, FORWARD, OUTPUT; mangle also supportedReplace the placeholder with a valid, authorized context for the installed security policy.
Set connection mark-j CONNMARK --set-mark 32mangle/PREROUTING or mangle/OUTPUTDoes not automatically set the current packet mark.
Save packet mark to connection-j CONNMARK --save-markmangle/PREROUTING or mangle/OUTPUTOpposite direction to restore-mark; requires a tracked connection.
Bypass connection tracking-j CT --notrackraw/PREROUTING or raw/OUTPUTNOTRACK is an equivalent target. Later filtering still applies.
Source NAT to interface address-j MASQUERADEnat/POSTROUTINGUses an outgoing-interface address; --to-ports requires a compatible transport protocol.
Accept packet-j ACCEPTfilter/INPUT, FORWARD, or OUTPUT are common examples.Accepts this traversal; a later table or hook may still drop it.
Drop packet-j DROPfilter/INPUT, FORWARD, or OUTPUT are common examples.Discards this packet; not a command to delete a connection.
Reject packet with response-j REJECT --reject-with icmp-port-unreachablefilter/INPUT, FORWARD, OUTPUT in traditional IPv4 iptablestcp-reset instead requires -p tcp. Responses remain subject to protocol rules.
Return from chain-j RETURNA user-defined chain in the selected tableResumes at a saved jump return point; otherwise the built-in policy applies. See notes for goto.
Redirect to this host-p tcp -j REDIRECT --to-ports 8080nat/PREROUTING or nat/OUTPUTThe port option requires TCP, UDP, DCCP, or SCTP. Without it, REDIRECT can change the address without a port rewrite.

Notes

  1. Matches in a rule are combined: all must succeed. Ordinary port options and multiport do not override each other.
  2. ACCEPT ends the current table traversal, while DROP discards the current packet. Neither is a userspace instruction to manage a whole connection.
  3. REJECT is an extension. Its default IPv4 response is ICMP port unreachable; the traditional kernel implementation restricts it to the filter table’s input, forwarding, and output hooks.
  4. RETURN resumes after a saved -j jump. A -g/--goto does not save a return point in the current chain; returning instead reaches an earlier jump caller or the built-in policy.
  5. NAT rules establish connection bindings. Later packets use the binding, including reverse translation. Address pools do not imply server health checks or a least-used-server guarantee.

See iptables Commands for explanations and cleanup examples, Chains and Extensions for hook restrictions, and Protocols for port-list syntax. Primary references are iptables(8), iptables-extensions(8), and the Linux IPv4 REJECT implementation.