Only scan networks and devices you own or have written permission to test. Scanning other people's systems can be illegal. Commands that start with sudo need root on Linux and macOS. On Windows, leave out sudo and use an administrator prompt; the installer includes Npcap, which nmap needs. Addresses such as 192.168.1.0/24 are examples.

Install and basics #

  • Install nmap
    Debian, Ubuntu
    sudo apt install nmap
    Red Hat, Fedora
    sudo dnf install nmap
    Alpine
    apk add nmap
    macOS
    brew install nmap
    Windows
    winget install Insecure.Nmap
  • Show the nmap versionLinux, macOS, Windows
    nmap --version
  • Scan nmap's own test server, which you're allowed to scanLinux, macOS, Windows
    nmap scanme.nmap.org
  • Scan one host's 1,000 most common portsLinux, macOS, Windows
    nmap 192.168.1.20
  • Scan a whole subnetLinux, macOS, Windows
    nmap 192.168.1.0/24
  • Scan a range of addressesLinux, macOS, Windows
    nmap 192.168.1.10-50
  • Scan the hosts listed in a fileLinux, macOS, Windows
    nmap -iL targets.txt
  • Leave some hosts out of a scanLinux, macOS, Windows
    nmap 192.168.1.0/24 --exclude 192.168.1.1,192.168.1.254
  • Scan an IPv6 addressLinux, macOS, Windows
    nmap -6 2001:db8::20

Host discovery #

  • Find which hosts are up, without scanning portsLinux, macOS, Windows
    nmap -sn 192.168.1.0/24
  • Find hosts on your local network using ARPLinux, macOS, Windows
    sudo nmap -sn -PR 192.168.1.0/24
  • Find hosts that block ping by probing port 443Linux, macOS, Windows
    nmap -sn -PS443 192.168.1.0/24
  • List the addresses a scan would cover, without scanningLinux, macOS, Windows
    nmap -sL 192.168.1.0/24
  • Scan a host even if it doesn't answer pingLinux, macOS, Windows
    nmap -Pn 192.168.1.20
  • Skip DNS lookups to speed up a scanLinux, macOS, Windows
    nmap -n 192.168.1.0/24
  • Show why nmap thinks a host or port is upLinux, macOS, Windows
    nmap --reason 192.168.1.20
  • Trace the route to each hostLinux, macOS, Windows
    nmap --traceroute scanme.nmap.org
  • Find hosts with ICMP echo (ping) requestsLinux, macOS, Windows
    sudo nmap -sn -PE 192.168.1.0/24
  • Find hosts with ICMP timestamp requestsLinux, macOS, Windows
    sudo nmap -sn -PP 192.168.1.0/24
  • Find hosts with ICMP address mask requestsLinux, macOS, Windows
    sudo nmap -sn -PM 192.168.1.0/24
  • Find hosts with UDP probesLinux, macOS, Windows
    sudo nmap -sn -PU53,161 192.168.1.0/24
  • Find hosts with TCP ACK probesLinux, macOS, Windows
    nmap -sn -PA80,443 192.168.1.0/24
  • Combine several discovery probes to find more hostsLinux, macOS, Windows
    sudo nmap -sn -PE -PS22,80,443 -PA80 -PU53 192.168.1.0/24
  • Look up names for every address, even hosts that are downLinux, macOS, Windows
    nmap -sn -R 192.168.1.0/24
  • Use specific DNS servers for name lookupsLinux, macOS, Windows
    nmap --dns-servers 1.1.1.1,8.8.8.8 192.168.1.0/24
  • Use your system's normal DNS resolverLinux, macOS, Windows
    nmap --system-dns 192.168.1.0/24
  • List the interfaces and routes nmap can useLinux, macOS, Windows
    nmap --iflist
  • Scan through a specific network interfaceLinux, macOS, Windows
    sudo nmap -e eth0 192.168.1.0/24
  • Scan hosts in a random orderLinux, macOS, Windows
    nmap --randomize-hosts 192.168.1.0/24

Port scans #

  • Scan specific portsLinux, macOS, Windows
    nmap -p 22,80,443 192.168.1.20
  • Scan a range of portsLinux, macOS, Windows
    nmap -p 1-1024 192.168.1.20
  • Scan all 65,535 portsLinux, macOS, Windows
    nmap -p- 192.168.1.20
  • Scan ports by service nameLinux, macOS, Windows
    nmap -p ssh,http,https 192.168.1.20
  • Scan the 100 most common ports (fast)Linux, macOS, Windows
    nmap -F 192.168.1.20
  • Scan the 20 most common portsLinux, macOS, Windows
    nmap --top-ports 20 192.168.1.20
  • Show only open portsLinux, macOS, Windows
    nmap --open 192.168.1.0/24
  • Run a TCP SYN scanLinux, macOS, Windows
    sudo nmap -sS 192.168.1.20
  • Run a full TCP connect scan, without rootLinux, macOS, Windows
    nmap -sT 192.168.1.20
  • Scan the most common UDP portsLinux, macOS, Windows
    sudo nmap -sU --top-ports 20 192.168.1.20
  • Scan TCP and UDP togetherLinux, macOS, Windows
    sudo nmap -sS -sU -p T:22,80,443,U:53,161 192.168.1.20
  • Map which ports a firewall filters (ACK scan)Linux, macOS, Windows
    sudo nmap -sA 192.168.1.20
  • Scan ports in order instead of randomlyLinux, macOS, Windows
    nmap -r 192.168.1.20
  • Leave some ports out of a scanLinux, macOS, Windows
    nmap -p 1-1024 --exclude-ports 25,110 192.168.1.20
  • Run a FIN scanLinux, macOS, Windows
    sudo nmap -sF 192.168.1.20
  • Run a NULL scanLinux, macOS, Windows
    sudo nmap -sN 192.168.1.20
  • Run an Xmas scanLinux, macOS, Windows
    sudo nmap -sX 192.168.1.20
  • Run a TCP Window scanLinux, macOS, Windows
    sudo nmap -sW 192.168.1.20
  • Run a Maimon scanLinux, macOS, Windows
    sudo nmap -sM 192.168.1.20
  • Set your own TCP flagsLinux, macOS, Windows
    sudo nmap --scanflags SYNFIN 192.168.1.20
  • Find which IP protocols a host supportsLinux, macOS, Windows
    sudo nmap -sO 192.168.1.20
  • Scan SCTP portsLinux, macOS, Windows
    sudo nmap -sY 192.168.1.20
  • Scan through an idle third host (zombie scan)Linux, macOS, Windows
    sudo nmap -Pn -sI 192.168.1.30 192.168.1.20

    Warning: Uses another device to send the scan. Only use hosts you own as the idle host.

Services and operating systems #

  • Find which software and version is on each open portLinux, macOS, Windows
    nmap -sV 192.168.1.20
  • Try harder to identify servicesLinux, macOS, Windows
    nmap -sV --version-intensity 9 192.168.1.20
  • Identify services quicklyLinux, macOS, Windows
    nmap -sV --version-light 192.168.1.20
  • Guess the operating systemLinux, macOS, Windows
    sudo nmap -O 192.168.1.20
  • Guess the operating system even when nmap isn't sureLinux, macOS, Windows
    sudo nmap -O --osscan-guess 192.168.1.20
  • Run OS detection, versions, default scripts and traceroute togetherLinux, macOS, Windows
    sudo nmap -A 192.168.1.20

    Warning: Easy for the target to notice and can trip intrusion alerts. Only run it on systems you're allowed to test.

Timing and performance #

  • Scan faster on a reliable networkLinux, macOS, Windows
    nmap -T4 192.168.1.0/24
  • Scan slowly and politelyLinux, macOS, Windows
    nmap -T2 192.168.1.20
  • Send at least 1,000 packets a secondLinux, macOS, Windows
    nmap --min-rate 1000 192.168.1.20
  • Retry each probe only onceLinux, macOS, Windows
    nmap --max-retries 1 192.168.1.0/24
  • Give up on a host after 5 minutesLinux, macOS, Windows
    nmap --host-timeout 5m 192.168.1.0/24
  • Wait a second between probesLinux, macOS, Windows
    nmap --scan-delay 1s 192.168.1.20
  • Show progress every 30 secondsLinux, macOS, Windows
    nmap --stats-every 30s 192.168.1.0/24

Firewall and IDS testing #

  • Split probes into small fragmentsLinux, macOS, Windows
    sudo nmap -f 192.168.1.20
  • Set the fragment sizeLinux, macOS, Windows
    sudo nmap --mtu 16 192.168.1.20
  • Send probes from a set source portLinux, macOS, Windows
    sudo nmap --source-port 53 192.168.1.20
  • Set the TTL on probesLinux, macOS, Windows
    sudo nmap --ttl 64 192.168.1.20
  • Add random data to probesLinux, macOS, Windows
    sudo nmap --data-length 25 192.168.1.20
  • Send probes with bad checksums to test the firewallLinux, macOS, Windows
    sudo nmap --badsum 192.168.1.20
  • Scan slowly to test whether the IDS noticesLinux, macOS, Windows
    nmap -T1 192.168.1.20
  • Hide your scan among random decoy addressesLinux, macOS, Windows
    sudo nmap -D RND:5 192.168.1.20

    Warning: Makes the target see traffic from addresses that aren't yours. Only use it on networks you're allowed to test.

  • Hide your scan among decoy addresses you chooseLinux, macOS, Windows
    sudo nmap -D 192.168.1.5,192.168.1.6,ME 192.168.1.20

    Warning: Makes the target see traffic from other addresses. Only use addresses and networks you're allowed to.

  • Use a random MAC address on your local networkLinux, macOS, Windows
    sudo nmap --spoof-mac 0 192.168.1.20
  • Send probes from another source IP addressLinux, macOS, Windows
    sudo nmap -S 192.168.1.99 -e eth0 -Pn 192.168.1.20

    Warning: Replies go to the address you set, not to you. Only use addresses you control.

  • Scan through a SOCKS proxyLinux, macOS, Windows
    nmap -sT -Pn --proxies socks4://127.0.0.1:1080 192.168.1.20

Output #

  • Show more detail as the scan runsLinux, macOS, Windows
    nmap -v 192.168.1.20
  • Save results as textLinux, macOS, Windows
    nmap -oN scan.txt 192.168.1.0/24
  • Save results as XMLLinux, macOS, Windows
    nmap -oX scan.xml 192.168.1.0/24
  • Save results in a grep-friendly formatLinux, macOS, Windows
    nmap -oG scan.gnmap 192.168.1.0/24
  • Save results in all formats at onceLinux, macOS, Windows
    nmap -oA scan 192.168.1.0/24
  • Resume a scan that was stoppedLinux, macOS, Windows
    nmap --resume scan.gnmap
  • Compare two scans to see what changedLinux, macOS, Windows
    ndiff old.xml new.xml
  • Turn XML results into an HTML reportLinux, macOS
    xsltproc scan.xml -o scan.html
  • Show even more detail as the scan runsLinux, macOS, Windows
    nmap -vv 192.168.1.20
  • Add to an existing results file instead of replacing itLinux, macOS, Windows
    nmap -oN scan.txt --append-output 192.168.1.0/24
  • List the hosts that were up from grep-friendly resultsLinux, macOS
    grep "Status: Up" scan.gnmap
  • List open ports from grep-friendly resultsLinux, macOS
    grep "/open/" scan.gnmap

Debugging #

  • Show debugging detailLinux, macOS, Windows
    nmap -d 192.168.1.20
  • Show every packet nmap sends and receivesLinux, macOS, Windows
    sudo nmap --packet-trace -p 80 192.168.1.20

Scripts (NSE) #

  • Run the default safe scriptsLinux, macOS, Windows
    nmap -sC 192.168.1.20
  • Run scripts that are safe to useLinux, macOS, Windows
    nmap --script safe 192.168.1.20
  • Run one scriptLinux, macOS, Windows
    nmap --script http-title -p 80,443 192.168.1.0/24
  • Pass options to a scriptLinux, macOS, Windows
    nmap --script http-title --script-args http.useragent="Mozilla/5.0" -p 80 192.168.1.20
  • Show help for a scriptLinux, macOS, Windows
    nmap --script-help http-title
  • Update the script databaseLinux, macOS, Windows
    sudo nmap --script-updatedb
  • Show a web server's page titleLinux, macOS, Windows
    nmap --script http-title -p 80,443 192.168.1.20
  • Show a web server's response headersLinux, macOS, Windows
    nmap --script http-headers -p 80,443 192.168.1.20
  • Show which HTTP methods a server allowsLinux, macOS, Windows
    nmap --script http-methods -p 80,443 192.168.1.20
  • Show a server's TLS certificateLinux, macOS, Windows
    nmap --script ssl-cert -p 443 192.168.1.20
  • List the TLS versions and ciphers a server supportsLinux, macOS, Windows
    nmap --script ssl-enum-ciphers -p 443 192.168.1.20
  • List the algorithms an SSH server supportsLinux, macOS, Windows
    nmap --script ssh2-enum-algos -p 22 192.168.1.20
  • Show what each service says when you connect (banners)Linux, macOS, Windows
    nmap --script banner 192.168.1.20
  • Find a Windows machine's name and version over SMBLinux, macOS, Windows
    nmap --script smb-os-discovery -p 445 192.168.1.20
  • Check whether SMB signing is requiredLinux, macOS, Windows
    nmap --script smb2-security-mode -p 445 192.168.1.20
  • Check for known vulnerabilitiesLinux, macOS, Windows
    nmap -sV --script vuln 192.168.1.20

    Warning: Easy for the target to notice and can trip intrusion alerts. Only run it on systems you're allowed to test.

  • Find subdomains by guessing common namesLinux, macOS, Windows
    nmap --script dns-brute example.com

    Warning: Easy for the target to notice and can trip intrusion alerts. Only run it on systems you're allowed to test.

  • Run scripts that are both default and safeLinux, macOS, Windows
    nmap --script "default and safe" 192.168.1.20
  • Run every HTTP scriptLinux, macOS, Windows
    nmap --script "http-*" -p 80,443 192.168.1.20

    Warning: Easy for the target to notice and can trip intrusion alerts. Only run it on systems you're allowed to test.

  • Run all discovery scriptsLinux, macOS, Windows
    nmap --script discovery 192.168.1.20

    Warning: Easy for the target to notice and can trip intrusion alerts. Only run it on systems you're allowed to test.

  • Run your own script fileLinux, macOS, Windows
    nmap --script ./my-script.nse 192.168.1.20
  • Show what scripts send and receiveLinux, macOS, Windows
    nmap --script http-title --script-trace -p 80 192.168.1.20
  • Check whether an FTP server allows anonymous loginLinux, macOS, Windows
    nmap --script ftp-anon -p 21 192.168.1.20
  • List the commands an SMTP server supportsLinux, macOS, Windows
    nmap --script smtp-commands -p 25 192.168.1.20
  • Check whether a mail server is an open relayLinux, macOS, Windows
    nmap --script smtp-open-relay -p 25 192.168.1.20

    Warning: Easy for the target to notice and can trip intrusion alerts. Only run it on systems you're allowed to test.

  • Show SNMP system informationLinux, macOS, Windows
    sudo nmap -sU --script snmp-info -p 161 192.168.1.20
  • Check whether a DNS server answers anyone (open resolver)Linux, macOS, Windows
    sudo nmap -sU --script dns-recursion -p 53 192.168.1.20
  • Test whether a DNS server allows zone transfersLinux, macOS, Windows
    nmap --script dns-zone-transfer --script-args dns-zone-transfer.domain=example.com -p 53 ns1.example.com
  • Show NTP server informationLinux, macOS, Windows
    sudo nmap -sU --script ntp-info -p 123 192.168.1.20
  • Show UPnP device informationLinux, macOS, Windows
    sudo nmap -sU --script upnp-info -p 1900 192.168.1.20
  • Show an SSH server's host keysLinux, macOS, Windows
    nmap --script ssh-hostkey -p 22 192.168.1.20
  • Show which login methods an SSH server allowsLinux, macOS, Windows
    nmap --script ssh-auth-methods --script-args ssh.user=root -p 22 192.168.1.20
  • Show the encryption Remote Desktop usesLinux, macOS, Windows
    nmap --script rdp-enum-encryption -p 3389 192.168.1.20
  • List the SMB versions a server supports, including SMBv1Linux, macOS, Windows
    nmap --script smb-protocols -p 445 192.168.1.20
  • List SMB sharesLinux, macOS, Windows
    nmap --script smb-enum-shares -p 445 192.168.1.20

    Warning: Easy for the target to notice and can trip intrusion alerts. Only run it on systems you're allowed to test.

  • Check for the EternalBlue (MS17-010) vulnerabilityLinux, macOS, Windows
    nmap --script smb-vuln-ms17-010 -p 445 192.168.1.20
  • Check for the Heartbleed vulnerabilityLinux, macOS, Windows
    nmap --script ssl-heartbleed -p 443 192.168.1.20
  • Show a web server's security headersLinux, macOS, Windows
    nmap --script http-security-headers -p 443 192.168.1.20
  • Show a website's robots.txtLinux, macOS, Windows
    nmap --script http-robots.txt -p 80,443 192.168.1.20
  • Look for common web pages and admin panelsLinux, macOS, Windows
    nmap --script http-enum -p 80,443 192.168.1.20

    Warning: Easy for the target to notice and can trip intrusion alerts. Only run it on systems you're allowed to test.

  • Show MySQL server informationLinux, macOS, Windows
    nmap --script mysql-info -p 3306 192.168.1.20
  • Show Microsoft SQL Server informationLinux, macOS, Windows
    nmap --script ms-sql-info -p 1433 192.168.1.20
  • List known CVEs for the versions foundLinux, macOS, Windows
    nmap -sV --script vulners 192.168.1.20

    Warning: Sends the software versions it finds to the vulners.com database.

  • Find DHCP servers on your networkLinux, macOS, Windows
    sudo nmap --script broadcast-dhcp-discover
  • Find hosts by broadcasting a pingLinux, macOS, Windows
    sudo nmap --script broadcast-ping
  • Find UPnP devices on your networkLinux, macOS, Windows
    sudo nmap --script broadcast-upnp-info

Handy scans for your own network #

  • Find web serversLinux, macOS, Windows
    nmap -p 80,443,8080,8443 --open 192.168.1.0/24
  • Find devices with SSH openLinux, macOS, Windows
    nmap -p 22 --open 192.168.1.0/24
  • Find devices with Remote Desktop openLinux, macOS, Windows
    nmap -p 3389 --open 192.168.1.0/24
  • Find devices still using TelnetLinux, macOS, Windows
    nmap -p 23 --open 192.168.1.0/24
  • Find printersLinux, macOS, Windows
    nmap -p 515,631,9100 --open 192.168.1.0/24
  • Find DNS serversLinux, macOS, Windows
    sudo nmap -sU -p 53 --open 192.168.1.0/24
  • Audit every port and service on one hostLinux, macOS, Windows
    nmap -p- -sV -T4 192.168.1.20
  • Check what your server exposes to the internetLinux, macOS, Windows
    nmap -Pn -p- 203.0.113.10
  • Find web admin pages on common portsLinux, macOS, Windows
    nmap -p 80,443,8000,8080,8443,9443 --open 192.168.1.0/24
  • Find databasesLinux, macOS, Windows
    nmap -p 1433,3306,5432,6379,27017 --open 192.168.1.0/24
  • Find file shares (SMB)Linux, macOS, Windows
    nmap -p 139,445 --open 192.168.1.0/24
  • Find VNC serversLinux, macOS, Windows
    nmap -p 5900-5910 --open 192.168.1.0/24
  • Find Proxmox serversLinux, macOS, Windows
    nmap -p 8006 --open 192.168.1.0/24
  • Find devices that answer SNMPLinux, macOS, Windows
    sudo nmap -sU -p 161 --open 192.168.1.0/24
  • Check the TLS setup of every web serverLinux, macOS, Windows
    nmap --script ssl-enum-ciphers -p 443 --open 192.168.1.0/24
  • Save an inventory of every host and serviceLinux, macOS, Windows
    nmap -sV -T4 -oX inventory.xml 192.168.1.0/24