What Is A Port Scanning? How To Prevent Port Scan Attacks

Image
What Is A Port Scanning? How To Prevent Port Scan Attacks
Port scanning maps open ports on a host. Learn scan types, tools, a how-to guide, a case study and a checklist to block port scan attacks.
Blog Author
Published on
Nov 16, 2026
Views
2135
Read Time
10 Mins
Table of Content

A port scan is a series of probe packets sent to a host to discover which network ports are open, closed or filtered. Port scanning is an early step in most reconnaissance: attackers use it to find weak entry points, and defenders use it to audit their exposure. A scan is only a probe and cannot be stopped from arriving, but the attack that follows it can be. 

To prevent port scan attacks, close unused ports, enforce default-deny firewall rules, deploy intrusion detection and monitor your logs. This guide covers scan types, tools, a tutorial with sample output, statistics, a real case study, a checklist and FAQs.

What Is Port Scanning and How Does It Work?

Port scanning sends connection requests to a host’s ports and reads the replies to identify which services are listening. A host has 65,535 TCP and 65,535 UDP ports, and each probe reveals one of three states.

How Does a Scan Read a Port?

The scanner sends a probe, usually a TCP SYN packet. A SYN-ACK reply means the service answers, a reset means nothing listens, and silence suggests a firewall is dropping traffic. Service banners can then reveal software names and versions.

What Are the Three Port States?

  • Open: a SYN-ACK reply shows the service is listening.

  • Closed: an RST reply shows the host is reachable but nothing listens.

  • Filtered: no reply, or an ICMP error, shows a firewall is blocking probes.

Why Do Attackers and Defenders Run Port Scans?

Attackers scan to find exploitable services. Defenders scan to find the same services first and shut them down.

What Do Attackers Look For?

Exposed remote-access and file-sharing ports such as RDP (3389), SSH (22) and SMB (445), plus outdated software that matches known exploits.

Why Do Defenders Scan Their Own Networks?

To build an asset inventory, confirm firewall rules work and meet compliance needs. Scanning networks you do not own without written permission can breach computer-misuse laws.

What Are the Main Types of Port Scans?

Port scanning techniques differ mainly in how much of the TCP handshake they complete, which affects speed and how easily they are noticed.

Scan type

How it works

Visibility to defenders

Best for

TCP connect

Completes the full handshake

High, always logged

Users without root

SYN (half-open)

Sends SYN, never completes

Medium

Fast default scan

UDP

Sends UDP packets, waits for ICMP errors

High, slow

DNS, SNMP, DHCP

FIN/NULL/Xmas

Sends unusual flag combinations

Lower against simple filters

Firewall testing

ACK

Sends ACK packets

Medium

Mapping firewall rules

Note: “stealth” is relative. Modern IDS tools detect SYN scans easily, and FIN, NULL and Xmas scans do not work reliably against Windows hosts.

SYN Scan vs TCP Connect: Which Is Better?

SYN scans are faster and leave fewer log entries because they never finish the handshake, but they need root privileges. Connection scans work for any user but are easily logged.

 
 
 
 
Advance Your IT Career with Our DevOps Course!

Which Tools Are Best for Scanning Open Ports?

Nmap is the best all-round choice, while Advanced Port Scanner suits quick Windows LAN checks. The following port scanning tools cover most needs:

  • Nmap (best for security professionals and learners): free and open source, with a scripting engine for version and vulnerability detection.
  • Advanced Port Scanner (best for Windows admins): A free tool that lists devices, open ports and shared folders in seconds.
  • Masscan (best for large-scale audits): the project describes it as a SYN-packet scanner that can sweep the entire Internet in under five minutes.
  • Angry IP Scanner (best for beginners): lightweight, cross-platform, with simple exports.
  • Online port scanner services (best for an outside view): no installation needed, and they scan from outside your network to show what the internet sees. A port checker is the simplest version, testing one port at a time.

How Do You Run a Port Scan Step by Step?

Get written permission, run Nmap’s SYN scan on your target, then verify from outside and close anything unneeded.

  1. Get permission: Scan only systems you own or are authorised in writing to test.
  2. Install a scanner: Run sudo apt install nmap on Linux, or use Advanced Port Scanner on Windows.
  3. Run a SYN scan: sudo nmap -sS -p 1-1024 192.168.1.10 checks the first 1,024 ports. By default, Nmap checks the 1,000 most common.
  4. Detect versions: sudo nmap -sV -p- 192.168.1.10 scans all 65,535 ports and identifies software. This can take a while.
  5. Check from outside: Repeat the scan with an online port scanner to see your public exposure.
  6. Act and re-test: Close or restrict every unneeded open port, then scan again.

How Do You Read the Results?

Here is a simplified, illustrative example of Nmap output (your results will differ):

Nmap scan report for 192.168.1.10

Host is up (0.0010s latency).

Not shown: 1021 filtered tcp ports (no-response)

PORT    STATE   SERVICE

22/tcp  open    ssh

80/tcp  closed  http

443/tcp open    https

  • Host is up: the target answered, so it is reachable.
  • Not shown: 1021 filtered: most ports gave no reply, so a firewall is probably dropping the probes. This is what a default-deny setup looks like from outside.
  • 22/tcp open: SSH is listening. Confirm it is needed, and restrict it to a VPN or allow-list.
  • 80/tcp closed: the host replied with a reset. It is reachable, but nothing is listening on this port.
  • 443/tcp open: a web service is exposed. Confirm it is intended and patched.

What Do the Statistics Say About Port Scan Risks?

Scanning is fast, constant and automated, and attackers increasingly turn what they find into breaches.

Statistic

Source

Attackers typically start scanning for vulnerabilities within 15 minutes of a CVE being announced.

Palo Alto Networks, 2022 Attack Surface Management Threat Report, via BleepingComputer

A Palo Alto signature for the F5 BIG-IP flaw CVE-2022-1388 triggered 2,552 times in a window from 4:47 to 14:00 UTC on 10 May 2022, days after F5 disclosed the flaw on 4 May.

Unit 42, Palo Alto Networks

Source IPs scanning port 3389 averaged about 2,600 per day from October to February, then rose to 3,540 per day in March 2020.

SANS Internet Storm Center

Vulnerability exploitation made up 31% of initial access vectors, ahead of phishing (16%) and credential abuse (13%). It is the first time credential theft has lost the top spot in the report’s 19-year history.

Verizon 2026 DBIR

In the fastest 25% of 2025 intrusions, attackers reached data exfiltration within 72 minutes of initial access, down from 285 minutes.

Unit 42 2026 Global Incident Response Report, via Cloud Security Alliance 

Which Real-World Attack Began With a Port Scan?

The WannaCry ransomware (May 2017) spread by hunting for open SMB port 445, turning routine scanning into worldwide damage.

How Did WannaCry Use Scanning?

According to Trend Micro, it scanned its local network for open port 445 and probed random internet addresses for the same port. On finding one, it scanned every device in that address’s /24 range. It then used the EternalBlue vulnerability to spread to other systems.

What Was the Lesson?

Trend Micro noted that organisations that had patched and properly configured SMB were not affected. Block port 445 at the perimeter, patch quickly and segment internal networks.

How Can You Detect a Port Scan on Your Network?

Look for one source IP touching many ports or hosts in a short time.

  • Many SYN packets to sequential ports from one IP (firewall and IDS logs)

  • Bursts of connection resets (server and firewall logs)

  • Probes with odd flags such as FIN, NULL or Xmas (Snort or Suricata alerts)

  • Slow probes spread over hours (SIEM correlation rules)

How Can You Prevent Port Scan Attacks?

You can't stop probes arriving, but you can prevent port scan attacks by making sure the probes find nothing useful: close unused ports, filter the rest and alert on scanning behaviour.

What Is the Prevention Checklist?

  • Disable unused services and close their ports

  • Apply a default-deny firewall that allows only required ports (dropping packets makes ports appear filtered; rejecting them makes ports appear closed)

  • Put RDP, SSH and SMB behind a VPN or IP allow-list

  • Deploy IDS/IPS rules that flag and block scanning sources

  • Rate-limit repeated connection attempts

  • Patch every internet-facing service

  • Re-test monthly with a port checker

What Does a Port Inventory Look Like?

Track every open port with its service, business need, owner, action and review date. This is a sample:

Port

Service

Needed?

Owner

Action

Last reviewed

22

SSH

Yes

Ops

Restrict to VPN

2026-11-01

3389

RDP

No

IT

Close

2026-11-01

445

SMB

No

IT

Block at perimeter

2026-11-01

What Is the Best Way to Stay Protected From Port Scans?

You cannot stop probes from arriving, because port scanning is a normal part of how the internet works, but you can control what those probes find. A scan only becomes an attack when it discovers an open port running unpatched or poorly protected software, as the WannaCry outbreak showed with SMB port 445.

To prevent port scan attacks, focus on a few habits:

  • Reduce your exposure: close unused ports and apply a default-deny firewall.

  • Protect remote access: keep RDP, SSH and SMB behind a VPN or IP allow-list.

  • Detect early: watch your logs and IDS alerts for one source touching many ports.

  • Patch quickly: attackers begin scanning within minutes of a new vulnerability being announced.

  • Re-test regularly: scan your own systems from the inside and outside, with permission, and track every open port in an inventory.

Start with a single scan of your own network today, then act on what it finds. Turning these checks into a repeatable routine is what makes the difference over time. To automate them in CI/CD pipelines, DevOps training is a natural next step.

What Do People Ask Most About Port Scans?

1. Is Port Scanning Legal?

Scanning your own systems, or those you have written permission to test, is legal. Unauthorised scanning may breach computer-misuse laws, depending on country and intent.

2. Can a Firewall Stop a Port Scan?

It cannot stop probes arriving, but a default-deny firewall makes ports appear filtered, and paired with an IDS it can block repeat scanners.

3. How Is a Port Scan Different From a Vulnerability Scan?

A port scan finds open ports and services; a vulnerability scan tests those services for known weaknesses.

4. What Is the Safest Way to Check Open Ports?

Use Nmap on your own network and a trusted online port scanner for the external view.

Sources

 

About Author
Akshat Gupta

Founder of Apicle technology private limited

founder of Apicle technology pvt ltd. corporate trainer with expertise in DevOps, AWS, GCP, Azure, and Python. With over 12+ years of experience in the industry. He had the opportunity to work with a wide range of clients, from small startups to large corporations, and have a proven track record of delivering impactful and engaging training sessions.

Are you Confused? Let us assist you.
+1
Explore DevOps Certification Training!
Upon course completion, you'll earn a certification and expertise.
Image Image Image Image

Trending Articles

The most effective project-based immersive learning experience to educate that combines hands-on projects with deep, engaging learning.
WhatsApp