Phase 02.02 · What's Listening

Port Scanning with Nmap

Host discovery told you which machines are alive. Port scanning asks the next question: on each live host, what is listening? Every network service waits behind a numbered port, and finding those open ports is how you turn a bare IP address into a list of things you can actually attack. Nmap is the standard tool for the job — this lesson covers how ports work, the states Nmap reports, the scan techniques that produce them, and how to choose what to scan.

01

Ports and port states

A single IP address can run dozens of services at once — a web server, a mail server, a database, a remote-login daemon. To keep them separate, the transport layer gives every host 65,535 numbered ports for TCP and another 65,535 for UDP. Picture them as numbered doors on the front of the machine: a web server listens at door 80 or 443, SSH at door 22, DNS at door 53. A port scan is simply you walking down the hallway, knocking on each door, and writing down which ones answer.

TCP is the connection-oriented protocol — it sets up a session with a handshake before any data flows, which gives a scanner a clear, reliable signal to read. UDP is connectionless: it fires packets with no handshake and often no reply at all, which is exactly what makes UDP scanning slow and ambiguous. Most of what follows is about TCP, with UDP called out where it differs.

When Nmap finishes probing a port, it does not just say "open" or "closed." It reports one of six states, and each one is a different piece of intelligence:

States are clues, not verdicts. A wall of filtered ports tells you a firewall stands between you and the host — that is a finding in itself. A mix of open and closed with no filtering tells you the host is exposed. Reading the pattern of states across a host is often more valuable than any single open port.
Lesson
02.02
Phase
Scanning
Tool
Nmap
02

The core scan techniques

Nmap can probe a port in several different ways, and the technique you pick changes the speed, the stealth, and even the meaning of the result. Each one sends a different combination of TCP flags and interprets the reply differently. The table below covers the techniques you will reach for most often.

ScanFlagHow it worksNotes
TCP Connect-sTCompletes the full three-way handshake (SYN → SYN/ACK → ACK) using the operating system's normal connect call, then closes the connection.Needs no root privileges, so it is the fallback when you are not running as a privileged user — but the full connection is logged by the target service, making it the loudest of the TCP scans.
SYN / half-open-sSSends a SYN, reads the reply (SYN/ACK means open, RST means closed), then tears the exchange down with an RST without completing the handshake.The default scan when Nmap runs as root. Faster than Connect and, because the handshake never finishes, historically less likely to be logged by the application.
UDP-sUSends UDP datagrams and watches for a reply or an ICMP "port unreachable" message. No handshake means lots of silence and lots of guessing.Slow and ambiguous, but essential — many critical services live on UDP, including DNS, SNMP, DHCP, and TFTP. Skip it and you miss them entirely.
FIN / Xmas / Null-sF / -sX / -sNSend unusual flag combinations — a lone FIN, every flag lit up (Xmas), or no flags at all (Null) — and exploit the RFC 793 rule that a closed port answers with RST while an open one stays silent.Built to slip past simple, stateless packet filters that only block SYN packets. Works on some TCP stacks but not on modern Windows, which replies with RST regardless, so results can mislead.
ACK-sASends a bare ACK packet. It never finds open ports — it watches whether the ACK gets through (unfiltered) or is dropped (filtered).A mapping tool, not a discovery tool. Use it to chart a firewall's rule set: which ports it filters and which it lets through.

Two of these stand apart. Connect and SYN are your everyday workhorses for finding open TCP ports; which one runs depends mostly on whether you have root. The FIN/Xmas/Null and ACK scans are situational — you reach for them when you are fighting a firewall or trying to stay quiet, not for routine discovery.

03

The SYN scan, step by step

Because the SYN scan is the default and the one you will run most, it is worth walking through exactly what happens on the wire. A normal TCP connection opens with a three-way handshake: the client sends a SYN, the server answers with SYN/ACK, and the client confirms with an ACK. Only after that third packet is the connection fully established and ready to carry data. The SYN scan deliberately stops short of finishing it.

Here is each possible outcome when Nmap fires a single SYN at a port:

The trick is that the connection never completes. Many older applications only logged a connection once the handshake finished — and since the SYN scan resets before that point, it left no entry in those logs. That is where the name "half-open" comes from, and why it was historically called a stealth scan. In practice modern firewalls and intrusion-detection systems watch for exactly this pattern, so it is far less invisible than it once was, but it remains faster and lighter than a full Connect scan, which is why it stays the default.

04

Choosing which ports to scan

By default, Nmap does not scan all 65,535 ports — it scans the 1,000 most common ones, a curated list of the ports services actually tend to use. That default is a deliberate trade-off: it finds the overwhelming majority of services quickly, but it is not exhaustive. A service deliberately moved to an unusual high port will sit there unseen. Knowing how to widen or narrow the range is part of scanning well:

The tension is always speed versus coverage. Scanning the default top-1000 is quick and catches almost everything; scanning every port with -p- is slow but complete. The mistake to avoid is assuming the fast scan is the whole picture — skipping -p- can hide a service deliberately tucked away on a high port, which is exactly where an attacker would put something they did not want found. A common rhythm is a fast scan first to get your bearings, then a full -p- sweep in the background to be certain.

05

Speed, stealth, and what comes next

Every scan you run is a balance of three pulls that fight each other: speed, stealth, and accuracy. Push for speed — faster timing, fewer ports, fewer retries — and you risk missing services or misreading filtered ports as closed. Push for stealth — slow timing, fragmented packets, exotic scan types — and a thorough scan can take hours. Push for accuracy — full port range, multiple retransmissions, careful timing — and you trade away both speed and quiet. There is no universal "best" scan; there is only the right scan for what you are trying to learn and how much noise you can afford to make.

Whatever the balance, remember what a port scan actually gives you: an open port is only half the story. Knowing that port 8080 is open does not tell you whether it runs a web server, a proxy, or some custom application — let alone which version, and whether that version has a known vulnerability. An open door is an invitation to look closer, not a conclusion.

That is exactly where the next lesson goes: service and version enumeration — getting Nmap to fingerprint the software behind each open port so you know precisely what you are dealing with. Before you move on, put this lesson into practice. Run real scans against safe targets in the Port Scanning Lab, and assemble your own commands flag by flag in the Nmap Scan Builder.