This article walks through ten concrete Nmap commands and techniques to list every device on your local network, from a quick ping sweep to OS fingerprinting and MAC address lookup. It’s written for system administrators, homelab owners, and anyone doing network inventory or security audits who wants real, copy-paste-ready commands with explanations of what each flag does and when to use it.
1. Basic Ping Sweep: nmap -sn 192.168.1.0/24
The go-to command for a fast device list is nmap -sn 192.168.1.0/24. The -sn flag tells Nmap to skip port scanning and only send ICMP echo requests, TCP SYN to port 443, TCP ACK to port 80, and ICMP timestamp requests by default. This returns each live host’s IP and MAC address (if you run as root) in seconds, making it perfect for a quick inventory. Replace the subnet with your own (check with ipconfig on Windows or ip a on Linux).
2. ARP Scan for Local Subnet: nmap -PR -sn 192.168.1.0/24
On a local Ethernet or Wi-Fi network, ARP is the most reliable way to find devices because it doesn’t rely on ICMP, which some hosts block. The -PR flag forces ARP ping, and combining it with -sn sends ARP requests to every IP in the range. This is faster and more accurate than ICMP-only scans on a LAN, and it reveals the MAC address of every responding device, which you can then use to identify the manufacturer via the OUI (first three bytes). Run it as root or with sudo to see MAC addresses.
3. List Only IPs with -oG or -oL
If you need a clean list of IPs for scripting or feeding into other tools, use output options. nmap -sn 192.168.1.0/24 -oG - | grep "Up$" | awk '{print $2}' extracts just the IPs from grepable output. Alternatively, -oL live_hosts.txt writes a plain list of IPs to a file. These are essential when you want to automate network discovery or pass results to a custom script.
4. TCP SYN Ping on Common Ports: nmap -PS22,80,443,3389 -sn
Some devices (especially Windows with firewall enabled) ignore ICMP echo requests. The -PS flag sends a TCP SYN packet to the specified ports; if the host responds with a RST or SYN/ACK, it’s up. For example, nmap -PS22,80,443,3389 -sn 192.168.1.0/24 probes the most common service ports. This is more likely to find firewalled hosts than a plain ping sweep, but it’s slower because it sends more packets.
5. UDP Ping for Devices That Block TCP/ICMP: nmap -PU53,161 -sn
Rarely, a device might block ICMP and TCP pings but respond to UDP. The -PU flag sends UDP packets to ports like 53 (DNS) or 161 (SNMP). If the host responds with an ICMP port unreachable, Nmap marks it as up. This is a niche but useful trick for network appliances or printers that behave oddly. Keep in mind that UDP scans are slower and may be filtered by some firewalls, so use this as a secondary check.
6. Find All Open Ports on Each Device: nmap -sT 192.168.1.0/24
Once you’ve listed devices, you often want to know what services they run. A TCP connect scan (-sT) completes the three-way handshake to each port in the default range (1-1000) and reports open ports. For example, nmap -sT 192.168.1.0/24 will show you which hosts have SSH (22), HTTP (80), or other services. This is more intrusive and slower, but it gives you a service inventory. Use -p- to scan all 65535 ports, but that’s time-consuming.
7. OS Detection to Identify Device Types: nmap -O 192.168.1.0/24
To know whether a device is a router, a printer, or a phone, run OS detection with -O. Nmap sends a series of TCP and UDP probes and compares the responses against a database of OS fingerprints. Example: nmap -O 192.168.1.0/24 will print the guessed OS (e.g., “Linux 2.6.32”, “Microsoft Windows 10”) for each host. This is invaluable for inventory, but it requires root privileges and can be inaccurate for devices with custom stacks. Combine with --osscan-guess to get more aggressive guesses.
8. MAC Address Lookup with -sP (Legacy) or -sn
To get the MAC address of each device, use nmap -sn 192.168.1.0/24 and look at the output lines that show “MAC Address: XX:XX:XX:XX:XX:XX (Vendor)”. The vendor name is derived from the OUI. This is the easiest way to identify devices without logging into them. For example, you might see “Apple” or “Raspberry Pi Foundation”. If you need to map IP to MAC for DHCP reservations, this is your quickest method.
9. Exclude Specific IPs or Ranges: nmap -sn 192.168.1.0/24 –exclude 192.168.1.1,192.168.1.5
When you’re scanning your network, you might want to skip certain hosts (like your router or a server) to avoid noise. The --exclude option lets you specify IPs or CIDR ranges to omit. Example: nmap -sn 192.168.1.0/24 --exclude 192.168.1.1,192.168.1.10-20. This is useful for focused scans on unknown devices or when you’re troubleshooting and want to ignore known infrastructure.
10. Save Full Results with -oA for Later Analysis
For a permanent record, use -oA basename to output in all three formats: normal, grepable, and XML. For example, nmap -sn 192.168.1.0/24 -oA network_scan creates network_scan.nmap, network_scan.gnmap, and network_scan.xml. The XML file can be imported into tools like Nmap’s Zenmap GUI or custom parsers. This is essential for documentation and for comparing scans over time to detect new or removed devices.
How to Choose
Choosing the right command depends on your goal. For a quick count of live hosts, start with -sn (ping sweep) and add -PR if you’re on a local network. If you need MAC addresses, run as root and use -sn; the ARP scan will give you that. If some devices don’t respond to ICMP, use -PS with common ports. For a full inventory including services, use -sT on a specific IP range. For device identification, use -O but be prepared for inaccuracies. Always consider the network size: scanning a /24 with -sn takes seconds, but a full port scan can take minutes. Also, check your permissions—running Nmap as root is required for ARP and OS detection.
Frequently Asked Questions
Q: Do I need to be root to list devices with Nmap?
A: Not for a basic ping sweep (-sn), but to see MAC addresses and use ARP scans (-PR) or OS detection (-O), you need root or sudo privileges.
Q: Why does my scan show fewer devices than my router’s DHCP list?
A: Devices that are turned off, in sleep mode, or have strict firewalls may not respond to pings. Also, some devices only respond to ARP, so use an ARP scan (-PR) to catch them.
Q: Can I scan a different subnet than my own?
A: Yes, but you’ll need to specify the target subnet and have network routes to it. For remote subnets, you may need to use a different ping type because ARP won’t cross routers.
Q: How do I find my network’s subnet mask and CIDR?
A: On Linux, run ip a; on Windows, ipconfig. Look for the IPv4 address and subnet mask; for example, 255.255.255.0 corresponds to /24.
Q: Is it legal to scan my own network?
A: Yes, scanning your own network is legal. Scanning someone else’s network without permission is illegal in many jurisdictions. Always get written consent before scanning any network you don’t own.
Q: What’s the difference between -sn and -sP?
A: They are the same; -sP is the older alias for -sn (ping scan, no port scan). Both are valid.
Final Thoughts
Nmap is the Swiss Army knife of network discovery, and these ten commands cover everything from a basic device list to detailed OS and service identification. Start with a simple ping sweep, then layer in ARP and TCP probes to catch stubborn hosts. Save your results with -oA to keep a record. Remember to run scans responsibly and only on networks you own or have permission to test. With these commands, you’ll have a complete picture of every device on your network in minutes.