This module matches a set of source or destination ports. Up to 15 ports can be specified. A port range (port:port) counts as two ports. It can only be used in conjunction with -p tcp or -p udp.
解决方法
每15个端口新增一条multiport的rule即可, 代码参考:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#!/bin/bash
all_ports="22,80,443,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46" ports_array=($(echo$all_ports | tr','' ')) ports="" for (( i=0; i<${#ports_array[@]}; i++ )); do ports+="${ports_array[$i]}," # One iptables multiports rule supports at most 15 ports if (( (i + 1) % 15 == 0 || i == ${#ports_array[@]} - 1 )); then ports=${ports%,} echo"ports: ${ports}" sudo iptables -I INPUT -p tcp -m multiport --dports ${ports} -j ACCEPT sudo iptables -I INPUT -p tcp -m multiport --sports ${ports} -j ACCEPT ports="" fi done