您可以使用不连续的 --dport 指定的 iptables 最大端口数?

use*_*029 3 linux iptables linux-networking

使用 --dport 参数可以在单个规则中指定多少个端口?。前任 -

iptables -A INPUT -p tcp --dport {0,5,10,15,20,25, etc,,??} -j ACCEPT
Run Code Online (Sandbox Code Playgroud)

Mad*_*ter 8

一,至少以这种方式;--dport(单独)不接受端口列表。

-m multiport允许使用端口列表,似乎受到一个变量的限制,该变量XT_MULTI_PORTS似乎在 15 处编译。快速测试表明 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
[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.
Run Code Online (Sandbox Code Playgroud)

(内核版本是4.1.6-201.fc22.x86_64。)