iptables Protocols

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

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

The -p or --protocol option selects an IP protocol. TCP and UDP provide transport-layer source and destination ports; protocols such as ICMP use different fields and do not have TCP/UDP port numbers.

Protocol-specific matches can be combined with other matches in one rule. Each condition must succeed. The examples below are rule fragments, not complete commands: the table, chain operation, other restrictions, and target belong to the surrounding rule.

Ordinary --sport/--dport options accept one port or one colon-separated range. A comma-separated list requires -m multiport; its list has at most 15 slots, with a range counting as two. That limit belongs to multiport, not to the number of ports covered by an ordinary range. These forms follow the extension manual.

TCP

TCP source and destination port examples:

-p tcp --sport 1024:65535
-p tcp --dport 443
-p tcp -m multiport --dports 22,80,443
-p tcp -m multiport --sports 80,443,8000:8005

--source-port and --destination-port are the long forms of --sport and --dport. For multiport, --source-ports/--sports and --destination-ports/--dports select lists. --ports matches either end.

TCP provides additional options, including flag matching. A port match alone does not establish the connection state; use an appropriate conntrack match when the rule needs that distinction.

UDP

UDP provides source and destination port matching without TCP flags:

-p udp --sport 53
-p udp --dport 5000:5010
-p udp -m multiport --dports 53,123
-p udp -m multiport --sports 53,5000:5010

The same distinction between one port/range and a multiport list applies. A UDP flow can have connection-tracking state even though UDP has no TCP-style handshake. See the command reference for state matching and target behavior.