3

How many ports can be specified in a single rule using the --dport argument?. Ex -

iptables -A INPUT -p tcp --dport {0,5,10,15,20,25, etc,,??} -j ACCEPT

1 Answer 1

9

One, at least in that manner; --dport (on its own) doesn't take a list of ports.

-m multiport enables the use of a list of ports, and that seems to be limited by a variable XT_MULTI_PORTS, which seems to be compiled-in at 15. A quick test suggests that 15 is indeed a limit:

[root@risby ~]# iptables -A INPUT -p tcp -m multiport --dports 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
[root@risby ~]# iptables -A INPUT -p tcp -m multiport --dports 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16
iptables v1.4.21: too many ports specified
Try `iptables -h' or 'iptables --help' for more information.

(Kernel version is 4.1.6-201.fc22.x86_64.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .