Skip to content
Tutorials Center
My learning

Topics

Lesson 9 of 31 ยท Scanning and Enumeration Concepts

How Port Scanning Works

Learn how connect, SYN and UDP scans decide that a port is open, closed or filtered, what timing does, and how to read Nmap output, with a simulated network model.

A port scan asks a host, one port at a time, "is anything listening here?" The answer tells you which services a machine exposes, which is the first thing both an attacker and a defender want to know. Nmap is the standard tool, and it ships with Kali. In this lesson you learn how the main scan types work, what the states open, closed and filtered really mean, how timing affects results, and how to read Nmap's report. The runnable part is a stand-in: a simulated network model that answers probes the way real hosts do.

Scan only systems you own or have written permission to test (Law, Ethics and Authorization), preferably in your own lab. The packet details come from TCP/IP Essentials for Security.

The three states

Nmap reports a state per port. These are inferences from replies, not facts read from the machine.

What a port can look like

Open A service answered the probe.
Closed The host replied, nothing listens.
Filtered No usable reply. A firewall may drop it.

Nmap also uses open|filtered when a probe gets no reply and it cannot tell which.

1 / 2

Connect scan

The TCP connect scan (nmap -sT) asks the operating system to open a normal connection. If the full handshake completes, the port is open. If the OS reports a refused connection, it is closed. It needs no special privileges, which makes it the default for unprivileged users. The downside: a completed connection is usually logged by the service, so it is noisy.

SYN scan

The SYN scan (nmap -sS, the default when run as root) crafts its own packets. It sends a SYN and watches the reply:

  • SYN+ACK: open. The scanner then sends RST instead of finishing the handshake.
  • RST: closed.
  • No reply, or an ICMP "unreachable" error: filtered.

Because the handshake never completes, applications often do not see a connection and log nothing, which is why this was once called "stealth". Modern firewalls and intrusion detection systems see it fine, so do not assume it is invisible. Building raw packets needs root, and it is faster than a connect scan.

UDP scan

UDP has no handshake, so nmap -sU is slower and less certain. Nmap sends a datagram to each port:

  • A UDP reply: open.
  • ICMP "port unreachable": closed.
  • Nothing: open|filtered, since an open service that ignores an empty probe looks exactly like a drop.

Many systems rate-limit ICMP errors, so a full UDP scan of 65,535 ports can take hours. Practitioners scan a short list of common UDP ports (53, 67, 123, 161) with protocol-specific payloads.

Timing

Scans trade speed against reliability and visibility. Nmap's timing templates run from -T0 (paranoid, one probe every few minutes) to -T5 (insane). -T3 is the default; -T4 is common on fast, reliable networks. Aggressive timing on a flaky link makes ports look filtered because replies are lost. Slow timing helps against rate-limited targets but takes much longer.

Two other choices matter: how many ports (-F for the top 100, -p- for all 65,535, --top-ports 1000 for the default) and whether to skip host discovery (-Pn assumes the host is up, useful when ping is blocked).

Reading Nmap output

This is a sample report for a fictional host. The block is read-only: the site cannot run Nmap.

Terminal
nmap -sS -p 1-1024 192.0.2.10
TEXT
Starting Nmap 7.x ( https://nmap.org ) at 2026-03-14 10:02 UTC
Nmap scan report for 192.0.2.10
Host is up (0.0021s latency).
Not shown: 1021 closed tcp ports (reset)
PORT    STATE    SERVICE
22/tcp  open     ssh
80/tcp  open     http
443/tcp open     https
445/tcp filtered microsoft-ds

Nmap done: 1 IP address (1 host up) scanned in 1.84 seconds

How to read it: "Not shown: 1021 closed tcp ports (reset)" means the host answered those ports with RST. The SERVICE column is a guess from a port-number table, not proof of what runs there (that is the job of version detection). 445 filtered means the probes got no answer: a firewall is likely in the way, and you learn that something is there to filter, but not what.

Useful output options are -oN file (normal text), -oX file (XML for tools) and -oG file (grep-friendly). Keep the scan output as evidence.

Stand-in: a simulated network

The first TryIt defines a fake host with a firewall policy and answers probes the way TCP does. Nothing here touches a real network.

Python Answer probes on a fake host

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 second TryIt shows why timing matters. A lossy link drops some replies; a scanner that sends each probe only once misreports open ports as filtered, while retries recover them. The loss pattern is generated from a fixed seed, so the output is the same every run.

Python Why retries and timing matter

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 real Nmap does the same thing at a larger scale: it estimates round-trip times, retransmits unanswered probes and slows down when it sees loss. The stand-in only shows the idea.

Defender's view

  • Scan yourself regularly from outside the firewall and compare the result with what you think is exposed.
  • Close or firewall services that need not be public; management ports (SSH, RDP, database ports) belong behind a VPN or allow list.
  • Alert on one source touching many ports or hosts in a short time.
  • Remember that filtering hides, it does not fix: patch services even if they are filtered.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. In a SYN scan, what does a reset (RST) reply mean?

    A reset is how a host rejects a connection attempt to a port with no listener.
  2. 2. Why does a UDP scan often report open|filtered?

    UDP has no handshake. Silence can mean an open service that did not answer or a firewall that dropped the datagram.
  3. 3. What is the main practical difference between -sT and -sS?

    The connect scan uses the normal connect call, so it is logged more often. The SYN scan builds its own packets and does not complete the handshake.
  4. 4. A port shows as filtered. What can you safely conclude?

    Filtered only describes the missing reply. It says nothing about whether a service sits behind the firewall.

Summary

  • A scan infers port state from replies: open, closed or filtered (plus open|filtered for UDP).
  • A connect scan uses full connections; a SYN scan sends a SYN and resets; a UDP scan sends datagrams and reads ICMP errors.
  • Timing and retries change accuracy: lost replies make open ports look filtered.
  • Nmap's service column is a table lookup; version detection comes next.
  • The Python code simulates hosts and loss; it is a stand-in, not a scanner.

Next: Service and Version Enumeration