How to nmap scan all ports
Content on WhatAnswers is provided "as is" for informational purposes. While we strive for accuracy, we make no guarantees. Content is AI-assisted and should not be used as professional advice.
Last updated: April 4, 2026
Key Facts
- Nmap scans ports from 1 to 65535 when using the `-p-` option.
- A full port scan can take a considerable amount of time, potentially hours.
- The `-p-` option is equivalent to `-p 1-65535`.
- Nmap's default scan typically checks the 1000 most common TCP ports.
- Scanning all ports can be resource-intensive on both the scanning machine and the target.
Overview
Network Mapper, commonly known as Nmap, is a powerful, free, and open-source utility for network discovery and security auditing. One of its primary functions is port scanning, which involves sending specially crafted packets to a target host to determine which ports are open, closed, or filtered. While Nmap's default scan is efficient, focusing on the 1000 most common ports, there are situations where a comprehensive scan of all possible ports is necessary. This is particularly useful in security audits, network inventory, or troubleshooting to ensure no services are running on unexpected ports.
Understanding Nmap Port Scanning
Nmap operates by sending probes to target ports and analyzing the responses. Different types of probes (like SYN, ACK, UDP) and scan techniques (like stealth scan, connect scan) yield different information and have varying levels of stealth and speed. The 'state' of a port can be one of the following:
- Open: An application is actively accepting connections on this port.
- Closed: The port is accessible, but there is no application listening on it.
- Filtered: A firewall, filter, or other network obstacle is blocking the probe, preventing Nmap from determining if the port is open or closed.
- Unfiltered: The port is accessible, but Nmap cannot determine if it is open or closed. This state is typically seen with ACK scans.
- Open|Filtered: Nmap cannot definitively determine if the port is open or filtered.
- Closed|Filtered: Nmap cannot definitively determine if the port is closed or filtered.
Scanning All Ports with Nmap
By default, Nmap scans the 1000 most common TCP ports. This is a good balance between speed and thoroughness for most common scenarios. However, to achieve a complete picture of a host's network surface, you need to instruct Nmap to check every single port. There are 65535 possible TCP ports and 65535 possible UDP ports.
The `-p-` Option
The most straightforward and commonly used method to scan all 65535 TCP ports is by using the `-p-` option with Nmap. This option tells Nmap to scan ports from 1 to 65535. The command would look like this:
nmap -p- <target_IP_address>This command will perform a TCP SYN scan (the default for privileged users) against all TCP ports on the specified target IP address. If you are running Nmap without root privileges, it will default to a TCP Connect scan.
Explicitly Specifying the Range
Alternatively, you can explicitly define the port range using the `-p` flag followed by the range:
nmap -p 1-65535 <target_IP_address>This command achieves the exact same result as `nmap -p- <target_IP_address>`. It's a matter of preference, though `-p-` is more concise.
Scanning All UDP Ports
If you need to scan all UDP ports as well, you must explicitly tell Nmap to do so, as Nmap's default scan only includes TCP ports. UDP scanning is generally slower and less reliable than TCP scanning because UDP is a connectionless protocol. To scan all 65535 UDP ports, you would use the `-sU` option along with the port specification:
nmap -sU -p- <target_IP_address>Or, to scan both all TCP and all UDP ports:
nmap -sS -sU -p- <target_IP_address> # For privileged users, defaults to SYN scan for TCPNote: Scanning UDP ports can be very slow, and results might be less conclusive than TCP scans.
Performance Considerations
Scanning all 65535 ports is a time-consuming operation. The duration depends on several factors:
- Network Latency: Higher latency means longer waits for responses.
- Target Host Responsiveness: A slow or overloaded host will take longer to respond to probes.
- Nmap Timing Options: Nmap has timing templates (e.g., `-T0` for paranoid, `-T5` for insane) that control the speed. Using faster templates can speed up the scan but increases the chance of detection and potential network instability.
- Firewalls and Intrusion Detection Systems (IDS): Aggressive scanning can be detected and blocked, or Nmap might spend a lot of time waiting for filtered responses.
A full port scan can take anywhere from a few minutes on a very fast, local network to several hours on a remote or heavily protected target. It is crucial to be mindful of the potential impact on network resources and performance, especially when scanning systems you do not own or administer.
Best Practices and Ethical Considerations
Always ensure you have explicit permission before scanning any network or host that you do not own. Unauthorized port scanning can be considered a hostile act and may have legal consequences. Use Nmap responsibly and ethically.
When to Scan All Ports
- Comprehensive Security Audits: To identify any potentially vulnerable services running on non-standard ports.
- Network Inventory: To get a complete picture of all active services on a network segment.
- Troubleshooting: When trying to diagnose connectivity issues or identify unexpected network traffic.
Alternatives and Refinements
If a full scan is too slow, consider:
- Scanning Specific Port Ranges: If you suspect a service might be running on a particular range (e.g., `-p 8000-9000`).
- Service Version Detection (`-sV`): After identifying open ports, use `-sV` to determine the specific software and version running, which can be more informative than just knowing a port is open.
- OS Detection (`-O`): To identify the operating system of the target.
In summary, while scanning all ports with Nmap using `-p-` provides the most comprehensive view of a target's open ports, it requires patience and careful consideration of network impact and ethical guidelines.
More How To in Daily Life
Also in Daily Life
More "How To" Questions
Trending on WhatAnswers
Browse by Topic
Browse by Question Type
Sources
- Nmap Reference Guide: Port Scanning TechniquesCC-BY-SA-4.0
- Nmap Scripting Engine Documentation: allports.nseCC-BY-SA-4.0
- Port Scanning - OWASPfair-use
Missing an answer?
Suggest a question and we'll generate an answer for it.