Pieter Breed Asked: 2010-10-15 02:00:35 +0800 CST2010-10-15 02:00:35 +0800 CST 2010-10-15 02:00:35 +0800 CST How can I open a range of ports in ubuntu using (g)ufw 772 I have to open up a group of ports. Adding the single ports to (g)ufw was easy enough but I can't work out how to open the range 11200-11299. How do I do that? firewall ufw gufw 5 Answers Voted Riccardo Murri 2010-10-15T09:05:09+08:002010-10-15T09:05:09+08:00 You can specify port ranges to ufw (the command-line one), using : (colon) to separate the lowest and the highest port in the range. For example: ufw allow 11200:11299/tcp Note that the protocol part (/tcp or /udp) is mandatory with port ranges. This works at least since Ubuntu 10.04. OJ LaBoeuf 2015-12-24T18:14:58+08:002015-12-24T18:14:58+08:00 Either ufw allow 11200:11299/tcp ufw allow 11200:11299/udp or if you need to use a from source ip range you must use full syntax ufw allow from AAA.BBB.CCC.DDD/EE to any port 11200:11299 proto tcp ufw allow from AAA.BBB.CCC.DDD/EE to any port 11200:11299 proto udp see: https://bugs.launchpad.net/ufw/+bug/1337767 Antony 2018-12-12T03:53:06+08:002018-12-12T03:53:06+08:00 Its worth adding that if you want to restrict to a specific IP address which is allowed access to those ports you can use the following: ufw allow proto tcp from 1.2.3.4 to any port 40000:40100 evgeny 2010-10-15T02:03:52+08:002010-10-15T02:03:52+08:00 I believe you can specify the range in the last tab of new rule, tick the checkbox at the bottom of the window to add more options (just to be safe). The range can be specified as 1000:1010 to open ports 1000-1010. Oli 2010-10-15T04:16:06+08:002010-10-15T04:16:06+08:00 The cleanest command line way I've seen is a little script like this: for i in `seq 11200 11299`; do ufw allow $i done
You can specify port ranges to
ufw
(the command-line one), using:
(colon) to separate the lowest and the highest port in the range. For example:Note that the protocol part (
/tcp
or/udp
) is mandatory with port ranges.This works at least since Ubuntu 10.04.
Either
or if you need to use a from source ip range you must use full syntax
see:
https://bugs.launchpad.net/ufw/+bug/1337767
Its worth adding that if you want to restrict to a specific IP address which is allowed access to those ports you can use the following:
ufw allow proto tcp from 1.2.3.4 to any port 40000:40100
I believe you can specify the range in the last tab of new rule, tick the checkbox at the bottom of the window to add more options (just to be safe). The range can be specified as 1000:1010 to open ports 1000-1010.
The cleanest command line way I've seen is a little script like this: