keepcalculator

06 Numbers and Powers

Nmap Command Examples for Scanning Networks

Card No. 06·86920 · Updated · Standard formula, shown below

Nmap (Network Mapper) is a free, open-source utility for network discovery and security auditing. You use it by typing nmap followed by options and a target (like an IP address or domain), and it returns a list of open ports, running services, and operating system guesses. The most basic example is nmap scanme.nmap.org, which scans the 1,000 most common ports on that host.

What Nmap Actually Does

Nmap works by sending crafted IP packets to a target and analyzing the responses. The most common scan type is the TCP SYN scan (-sS), which sends a SYN packet (like a connection request) and watches for a SYN-ACK (port open) or RST (port closed). Because the handshake is never completed, the connection is not established, making it stealthier than a full connect scan (-sT). Other probe types include UDP (-sU), ACK (-sA), and ICMP ping sweeps (-sn).

After port discovery, Nmap can run service/version detection (-sV) by sending a series of probes and matching the responses against a database. Operating system detection (-O) uses TCP/IP fingerprinting—comparing quirks in the target’s responses to known OS signatures. Script scanning (-sC) runs a set of Lua scripts for things like checking for default credentials or vulnerabilities.

Essential Command Examples

Here are the commands you will actually type, with what each does:

  • nmap 192.168.1.1 – scan the 1,000 most common ports on one IP.
  • nmap 192.168.1.0/24 – scan an entire subnet (all 254 hosts).
  • nmap -p 22,80,443 example.com – scan specific ports.
  • nmap -p 1-65535 example.com – scan all 65,535 TCP ports.
  • nmap -sU -p 53,123 example.com – scan UDP ports (DNS, NTP).
  • nmap -sV -p 22 example.com – detect the SSH version.
  • nmap -O example.com – guess the operating system (requires root).
  • nmap -sn 192.168.1.0/24 – ping sweep, list live hosts without port scan.
  • nmap -sC -sV example.com – run default scripts and version detection.
  • nmap -T4 -F example.com – fast scan (100 ports) with aggressive timing.

How to Choose the Right Scan

Pick the scan type based on your goal and your permission level:

  1. Quick check – use -F (fast) to scan the top 100 ports.
  2. Full port list – use -p- for all ports, but expect it to take much longer.
  3. Service version – add -sV; this is slower but tells you what software is running.
  4. OS detection – add -O; requires root and may be inaccurate on firewalled hosts.
  5. UDP services – use -sU; UDP scanning is slow and unreliable, so target specific ports.
  6. Firewall evasion – use -sA to map firewall rules, or -f to fragment packets.

For most everyday checks, -sV and -sC together give the most useful output. But remember: version detection and scripts generate more traffic and take longer.

Common Problems and How to Fix Them

  • Scan is too slow – increase timing with -T4 or -T5, or reduce ports with -F or -p.
  • Host seems down but is up – Nmap defaults to ICMP echo and port 80/443 checks. Use -Pn to skip host discovery and scan anyway.
  • Permission denied – SYN scan, OS detection, and UDP scan need root. Use sudo or switch to -sT (connect scan) which works as a normal user.
  • Firewall blocks probes – try -sT (full connect) or -sA (ACK) which may pass through simpler filters.
  • Results show “filtered” – that means a firewall dropped the packet; you cannot tell if the port is open or closed.
  • Scanning your own network is fine, scanning others is not – always get written permission. Unauthorized scanning is illegal in many jurisdictions.

Safety and Legality

Nmap is a dual-use tool. Running it against your own machines or a lab network is a standard learning exercise. Running it against a third-party network without explicit permission is considered hostile reconnaissance and can be a crime under computer misuse laws (e.g., the US Computer Fraud and Abuse Act, UK Computer Misuse Act). To practice safely, use your own router, a virtual machine, or the public test host scanme.nmap.org, which Nmap’s developers maintain for this purpose. Even then, keep scans light and avoid aggressive timing.

Alternatives and Comparisons

Nmap is not the only port scanner. Masscan is extremely fast, scanning the entire internet in minutes, but it lacks Nmap’s service detection and scripting. Zmap is similar, designed for large-scale internet-wide scans. Angry IP Scanner is a friendly GUI tool for simple ping sweeps and port checks. Netcat can manually probe a single port but is not a scanner. For network discovery, tools like arp-scan find hosts on the local LAN using ARP, which Nmap’s -PR flag also does. Nmap remains the best all-rounder because it combines discovery, port scanning, version detection, OS fingerprinting, and scripting in one tool.

Frequently Asked Questions

What does “open” vs “filtered” mean in Nmap output?

“Open” means the target responded with a packet that indicates a service is listening. “Filtered” means Nmap received no response or an error packet, usually because a firewall dropped the probe. It does not tell you whether a service is actually running behind the firewall.

How long does an Nmap scan take?

It depends on the number of ports, the timing template (-T0 to -T5), network latency, and whether you use version detection. A default 1,000-port scan on a local host might take 10–30 seconds; a full 65,535-port scan with -sV can take many minutes or hours on a slow link.

Do I need root to run Nmap?

Only for certain scan types. SYN scan (-sS), UDP scan (-sU), and OS detection (-O) require raw packet privileges, so you need root or sudo. The connect scan (-sT) and ping sweep (-sn) work as a normal user.

Can Nmap detect all services on a port?

No. Version detection (-sV) matches a database of known service signatures. If a service is custom, rare, or deliberately obfuscated, Nmap may report “unknown” or a generic guess. Also, some services only respond after a proper protocol handshake, which Nmap may not complete.

What is the difference between -sS and -sT?

-sS (SYN scan) sends a SYN packet and looks for SYN-ACK; it never completes the handshake, so it is stealthier and faster. -sT (connect scan) uses the operating system’s TCP connect function, completing the full handshake; it is slower and appears in application logs, but works without root.

How do I scan IPv6 addresses?

Add the -6 option, e.g., nmap -6 fe80::1. Nmap handles IPv6 the same way as IPv4, but some scan types (like OS detection) are less accurate on IPv6.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →