Chart: iptables Command Matrix
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
| Purpose | Rule fragment | Valid example placement | Qualification |
|---|---|---|---|
| Source port | -p tcp --sport 1024:65535 | filter/INPUT | TCP or UDP ordinary port/range matching; not ICMP. |
| Destination port | -p udp --dport 53 | filter/OUTPUT | One port or colon-separated range. |
| Destination address interval | -m iprange --dst-range 192.0.2.10-192.0.2.20 | filter/FORWARD | An address interval, not CIDR syntax. |
| Source address interval | -m iprange --src-range 192.0.2.10-192.0.2.20 | filter/INPUT | Use -s for a source CIDR prefix. |
| Source MAC address | -m mac --mac-source 02:00:00:00:00:01 | filter/INPUT or filter/FORWARD | Also usable in PREROUTING where the table supports it. Requires a suitable received Ethernet frame. |
| Packet mark | -m mark --mark 32 | mangle/PREROUTING | Reads packet metadata; does not set it. |
| Destination port list | -p tcp -m multiport --dports 80,443,8000:8005 | filter/INPUT | 15 slots maximum; a range counts as two. |
| Source port list | -p udp -m multiport --sports 53,123 | filter/OUTPUT | TCP, UDP, UDP-Lite, DCCP, or SCTP. |
| Socket group owner | -m owner --gid-owner 1000-1005 | filter/OUTPUT or mangle/POSTROUTING | Local originating socket; numeric ranges use a hyphen. |
| Socket user owner | -m owner --uid-owner 1000 | filter/OUTPUT or mangle/POSTROUTING | Not a remote user identity or a forwarded-packet attribute. |
| Destination address/prefix | -d 198.51.100.0/24 | filter/FORWARD | Address match; no transport protocol required. |
| Source address/prefix | -s 192.0.2.0/24 | filter/INPUT | Address match; no transport protocol required. |
| Connection mark | -m connmark --mark 32 | mangle/PREROUTING | Reads the tracked connection mark, not the packet mark. |
| Connection state | -m conntrack --ctstate ESTABLISHED,RELATED | filter/INPUT | The 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.
| Purpose | Rule fragment | Placement | Qualification |
|---|---|---|---|
| Restore connection mark to packet | -j CONNMARK --restore-mark | mangle/PREROUTING or mangle/OUTPUT | Requires a tracked connection. Position it before the routing decision that needs the mark. |
| Copy security label | -j CONNSECMARK --save or -j CONNSECMARK --restore | security/INPUT, FORWARD, OUTPUT; mangle also supported | Copies only into an unlabeled connection or packet; separate from routing marks. |
| Destination NAT | -j DNAT --to-destination 192.0.2.10:8080 | nat/PREROUTING or nat/OUTPUT | This port form requires TCP, UDP, DCCP, or SCTP. Does not itself allow delivery/forwarding. |
| Source NAT | -j SNAT --to-source 198.51.100.10 | nat/POSTROUTING; nat/INPUT since Linux 2.6.36 | Adding :PORT changes the source port, not the destination port. |
| Set packet mark | -j MARK --set-mark 32 | Use 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_CONTEXT | security/INPUT, FORWARD, OUTPUT; mangle also supported | Replace the placeholder with a valid, authorized context for the installed security policy. |
| Set connection mark | -j CONNMARK --set-mark 32 | mangle/PREROUTING or mangle/OUTPUT | Does not automatically set the current packet mark. |
| Save packet mark to connection | -j CONNMARK --save-mark | mangle/PREROUTING or mangle/OUTPUT | Opposite direction to restore-mark; requires a tracked connection. |
| Bypass connection tracking | -j CT --notrack | raw/PREROUTING or raw/OUTPUT | NOTRACK is an equivalent target. Later filtering still applies. |
| Source NAT to interface address | -j MASQUERADE | nat/POSTROUTING | Uses an outgoing-interface address; --to-ports requires a compatible transport protocol. |
| Accept packet | -j ACCEPT | filter/INPUT, FORWARD, or OUTPUT are common examples. | Accepts this traversal; a later table or hook may still drop it. |
| Drop packet | -j DROP | filter/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-unreachable | filter/INPUT, FORWARD, OUTPUT in traditional IPv4 iptables | tcp-reset instead requires -p tcp. Responses remain subject to protocol rules. |
| Return from chain | -j RETURN | A user-defined chain in the selected table | Resumes 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 8080 | nat/PREROUTING or nat/OUTPUT | The port option requires TCP, UDP, DCCP, or SCTP. Without it, REDIRECT can change the address without a port rewrite. |
Notes
- Matches in a rule are combined: all must succeed. Ordinary port options and multiport do not override each other.
ACCEPTends the current table traversal, whileDROPdiscards the current packet. Neither is a userspace instruction to manage a whole connection.REJECTis an extension. Its default IPv4 response is ICMP port unreachable; the traditional kernel implementation restricts it to thefiltertable’s input, forwarding, and output hooks.RETURNresumes after a saved-jjump. A-g/--gotodoes not save a return point in the current chain; returning instead reaches an earlier jump caller or the built-in policy.- 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.