Open range ports via ufw or iptables

For UFW

ufw allow from any to any port 4000:4020 proto tcp

For iptables

iptables -A tableName -p tcp  --match multiport --dports port1,port2 -j ACCEPT

iptables -A tableName -p udp  --match multiport --dports port1,port2 -j DROP

iptables -A tableName -p protocol  --match multiport --dports portRange1:PortRange2 -j ACCEPT

iptables -A tableName -p tcp  --match multiport --sports port1,port2 -j ACCEPT

iptables -A tableName -p udp  --match multiport --sports port1,port2 -j DROP

iptables -A tableName -p protocol  --match multiport --sports portRange1:PortRange2 -j ACCEPT

Written on March 15, 2017