Skip to content
Tutorials Center
My learning

Topics

Lesson 15 of 36 ยท Port Scanning Techniques

UDP Scanning with Nmap

Learn how the Nmap UDP scan works, why it is slow and ambiguous, how ICMP rate limiting affects it, and how to combine it with -sV, top ports and timing.

Most beginners scan only TCP, but a lot of important services run on UDP: DNS (53), DHCP (67/68), NTP (123), SNMP (161), TFTP (69), many VPNs (500, 4500, 1194), and plenty of games and streaming protocols. A forgotten UDP service such as an exposed SNMP agent with the default community string is a classic finding. Scanning UDP is harder, slower and more ambiguous than scanning TCP, but with the right expectations and options you can do it well.

Commands are read-only. Scan only systems you are authorized to test. The Python editors model replies and timing with plain data; nothing is transmitted.

Why UDP is different

TCP has a handshake: an open port answers SYN with SYN-ACK. UDP has none. When you send a UDP datagram to a port:

  • If a service is listening and understands the data, it may reply (or may not).
  • If nothing listens, the operating system usually returns an ICMP port unreachable message (type 3, code 3).
  • If a firewall drops the packet, nothing returns at all.

So an open port and a filtered port can look identical (silence), and closed ports reveal themselves through ICMP, which routers and hosts often rate-limit. Linux, for example, allows only about one ICMP error per second by default for UDP, so a closed-port sweep must slow down to match.

Running a UDP scan: -sU

Terminal
sudo nmap -sU 192.0.2.10                 # default: the 1000 most common UDP ports
sudo nmap -sU --top-ports 20 192.0.2.10  # a quick look at the most common 20
sudo nmap -sU -p 53,67,123,161 192.0.2.10

Raw packets need root. Example output (invented):

TEXT
Not shown: 996 closed udp ports (port-unreach)
PORT    STATE         SERVICE
53/udp  open          domain
123/udp open          ntp
161/udp open|filtered snmp
69/udp  open|filtered tftp

Example output. open ports replied with data; open|filtered ports stayed silent: they might be open and waiting for a valid request, or a firewall may be dropping the probe. Nmap cannot tell them apart without more information, as described in Port States Explained.

How Nmap resolves the ambiguity

  • For well-known ports (53, 123, 161, 137, 1900 and others), Nmap sends a protocol-specific payload, a real DNS query, an NTP request, an SNMP GET, taken from nmap-payloads. A real service answers a real request, so the port can be marked open.
  • With version detection (-sV), Nmap sends more probes to open|filtered ports and can promote them to open when a reply arrives.
  • It retransmits a few times: a single lost datagram would otherwise cause wrong results.
Terminal
sudo nmap -sU -sV --version-intensity 0 -p 53,123,161 192.0.2.10

(--version-intensity 0 keeps the extra probes light, which fits UDP's slowness.)

flowchart TD
  P["UDP probe sent"] --> R{"What came back?"}
  R -- "UDP data" --> O["open"]
  R -- "ICMP port unreachable (3/3)" --> C["closed"]
  R -- "other ICMP unreachable" --> F["filtered"]
  R -- "nothing after retries" --> OF["open|filtered"]

Figure: how a UDP probe's reply sets the port state.

Why it is slow, and how to speed it up

The slowness has two causes: ICMP rate limiting (one error per second means 1000 ports take about 17 minutes at best) and silent ports that need retransmissions. Remedies:

  1. Scan fewer ports. --top-ports 20 or a hand-picked list is often enough: -p 53,67,69,123,137,161,500,1194,5353.
  2. Use -sUV carefully on only the ports you care about.
  3. Raise timing a notch (-T4) on a reliable, authorized network, see Evasion, Timing and Ethics.
  4. Cut retries with --max-retries 1, accepting a few wrong open|filtered answers.
  5. Set a host time limit: --host-timeout 10m stops a host that would take too long.
  6. Scan TCP and UDP together: sudo nmap -sS -sU -p T:22,80,U:53,161 target finishes TCP quickly while UDP takes its time.
  7. Run it in the background and read the log (-oA) when it finishes.

What to look for when scanning your own network

UDP services that commonly deserve a second look:

Port Service Why check
53 DNS Open resolvers can be abused for amplification attacks
69 TFTP No authentication; used for device configs
123 NTP Old servers can be abused for amplification
137-138 NetBIOS Leaks names and details on Windows networks
161 SNMP Default community strings expose device data
500, 4500 IPsec VPN Confirm only the VPN gateway answers
1900 UPnP/SSDP Often should not be reachable from outside
5353 mDNS Local discovery; should stay on the LAN

A stand-in: the UDP classification table

This function applies the table you learned. Given what came back, it chooses a state and a reason, including the ICMP code details.

Python Classify UDP probe replies

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

A stand-in: why ICMP rate limiting hurts

If the target answers closed ports at no more than one ICMP error per second, scanning N closed ports needs about N seconds. This model estimates time for different port counts and shows why a short port list wins.

Python Estimate UDP scan time under ICMP rate limiting

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The numbers are a rough model, not a benchmark. The lesson: limit ports, and be patient. A full 65,535-port UDP scan of a rate-limited host takes the better part of a day.

Defensive view

If you run a service, check three things from the outside: which UDP ports answer, whether they need to be reachable from where the scan came from, and whether any answer leaks information (SNMP community, TFTP files, NetBIOS names). Compare your results with what the firewall policy says should be open. Chapter 8 shows how to save and compare results (Reporting and Automation).

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does Nmap report for a UDP port that returns no reply after retries?

    Silence is ambiguous: the port may be open and quiet, or a firewall may drop the probe.
  2. 2. Which reply makes a UDP port 'closed'?

    A closed UDP port causes the host to send ICMP port unreachable.
  3. 3. Why is a UDP scan slow on many systems?

    Hosts limit how many ICMP errors they send, and silent ports require waiting and retrying.
  4. 4. Which option is a good way to scan UDP faster on a trusted lab network?

    Fewer ports and fewer retries reduce time; accept some ambiguity in exchange.

Summary

  • -sU scans UDP; it needs root and is far slower than TCP scanning.
  • Replies: data means open, ICMP port unreachable means closed, silence means open|filtered.
  • Protocol-specific payloads and -sV resolve ambiguity for known services.
  • Speed up with fewer ports, fewer retries and sensible timing; combine with a TCP scan.
  • Exposed SNMP, TFTP, NTP and DNS services are frequent audit findings.

Next: Null, FIN and Xmas Scans