How To Scan All TCP and UDP Ports with Nmap?
Nmap is very useful and popular tool used to scan ports. Nmap by default scans most popular 1000 ports. We may need to change the port range and protocol type to all while scanning with nmap.
Scan All TCP Ports with Range
We can specify the port range with the
-p option. As we know TCP port numbers are between
65535 . We will use
-p0-65535 as option in order to scan all TCP ports. We do not specify the TCP protocol because default protocol for nmap port scan is TCP.
$ nmap -p0-65535 192.168.122.1
Faster Scan For All Ports
If we are scanning all ports this will take a lot of time. If the situation is not critical we can use faster scan with
-T5 parameter. This is the fastest scan level for nmap. This option can be used for UDP scans too.
$ nmap -p0-65535 192.168.122.1 -T5
Scan All TCP Ports
Another way to specify all TCP ports is dash. We can use
-p- which is more practical then port range specification.
$ nmap -p- 192.168.122.1
Scan All UDP Ports with Range
Nmap uses TCP as default protocol for port scan. We should explicitly specify the UDP protocol for UDP port scan. We will use same port range specification used in TCP. We will use
-sU for UDP protocol specification.
$ nmap -sU -p0-65535 192.168.122.1
Scan All UDP Ports
We will use
-p- to specify all ports easily.
$ nmap -sU -p- 192.168.122.1
Scan All TCP UDP Ports
We can scan all UDP and TCP ports in a single command. We will use
-sU for UDP and
sT for TCP protocol.
$ nmap -sU -sT -p0-65535 192.168.122.1