Selecting Ports for Scanning
By default, Nmap scans the top 1000 most popular ports for each requested protocol. Alternatively, you can use the -F (fast) flag to scan only the top 100 ports for each protocol or use the --top-ports flag to specify the desired number of ports for the scan.
Selecting the ports to scan is also possible using the -p switch. This can be somewhat complicated, so here are a few examples.
-p 22 Scan one port (in this case port 22) by providing only the desired number as the -p argument.
-p ssh Port names can be given instead of numbers. Note that a name can correspond to multiple ports.
-p 22,25,80 Multiple ports can be separated by a comma.
-p80-85,443,8000-8005,8080-8085 Port ranges can be specified by separating the start and end ports with a dash. Multiple ranges or individual ports can be specified separated by commas. This option scans ports 80, 81, 82, 83, 84, 85, 443, 8000 etc.
-p-100,60000- You can leave out the beginning of the range. In this example, ports from one hundred to six thousand are scanned, including all ports that are greater than or equal to sixty thousand.
-p- Leave out the initial and final numbers to scan the entire range (excluding zero). This scans all existing ports.


Ready to become an ethical hacker?
Start today.
As a member of Hakatemia you get unlimited access to Hakatemia modules, exercises and tools, and you get access to the Hakatemia Discord channel where you can ask for help from both instructors and other Hakatemia members.