Skip to content

/commands/nmap/nmap-scan-specific-ports

nmap -p: scan specific ports, port ranges or all 65535 ports

The commands on this page have not been executed by our verification runner yet.updated
tool
Nmap
versions
Nmap 7.x
os
linux, macos, windows

nmap -p 22,80,443 HOST scans only the listed ports. Ranges use a hyphen (-p 1-1024), -p- scans all ports from 1 to 65535, and without -p nmap scans the 1,000 most common ports for each protocol. Prefix ports with T: or U: to mix TCP and UDP in one scan (-p U:53,T:22,80 together with -sU and a TCP scan type).

Port specification

OptionScans
-p 22one port
-p 22,80,443a list
-p 1-1024a range
-p-all ports 1-65535
-p http,httpsports by service name (from nmap-services)
-p U:53,T:22,80UDP 53 and TCP 22 and 80 (needs -sU plus a TCP scan type)
-Fthe 100 most common ports (fast scan)
--top-ports 200the 200 most common ports
--exclude-ports 25everything selected except port 25

Examples

bash
nmap -p 22,80,443 scanme.nmap.org          # three TCP ports
nmap -p- 127.0.0.1                          # every TCP port on this machine
nmap -p 80,443 --open 192.168.1.0/24        # only hosts with these ports open, on your own LAN
sudo nmap -sU -p 53,123 127.0.0.1           # UDP needs privileges
nmap -sV -p 22 127.0.0.1                    # also detect the service version

Port states

StateMeaning
openan application accepts connections on the port
closedthe host answered, but nothing listens there
filteredno answer or an ICMP error, usually a firewall drops the packets
unfilteredreachable, but nmap cannot tell open from closed (ACK scan)
open|filteredno response, common for UDP: open or filtered

--open hides closed and filtered ports from the output. -oG - or -oX file.xml write results in grepable or XML form for scripts.

Check your own machine without nmap

To see which ports your own host listens on, the system tools are faster and need no scan: ss -ltnu on Linux, lsof -nP -iTCP -sTCP:LISTEN on macOS, netstat -ano on Windows.

Sources