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

Quick Answer: To Nmap scan all ports, you can use the `-p-` option, which tells Nmap to scan ports from 1 to 65535. Alternatively, you can specify a range like `-p 1-65535` for the same effect. This comprehensive scan ensures no port is missed, but it can take significantly longer than default scans.

Key Facts

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:

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 TCP

Note: 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:

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

Alternatives and Refinements

If a full scan is too slow, consider:

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.

Sources

  1. Nmap Reference Guide: Port Scanning TechniquesCC-BY-SA-4.0
  2. Nmap Scripting Engine Documentation: allports.nseCC-BY-SA-4.0
  3. Port Scanning - OWASPfair-use

Missing an answer?

Suggest a question and we'll generate an answer for it.