×

Port Scanning Explained: From TCP Handshake to Security Assessment in Practice

Port scanning is fundamental to network security assessment. This article covers TCP handshake mechanics, compares scanning techniques, and teaches result interpretation and defense strategies.

Port-scanning types and risk-assessment diagram
Illustration: Port-scanning types and risk-assessment diagram

Port Basics: Why 65,535?

RangeCategoryExamples
0–1023Well-Known22 (SSH), 80 (HTTP), 443 (HTTPS)
1024–49151Registered3306 (MySQL), 5432 (PostgreSQL)
49152–65535EphemeralOS-assigned for client connections

TCP Handshake & Scanning

SYN
SYN-ACK
ACK
Connected
TypeSendsOpenClosedNotes
TCP ConnectFull handshakeSYN-ACKRSTReliable; logged
SYNSYN onlySYN-ACKRSTFast, stealthy; root needed
FINFINNo responseRSTBypasses some firewalls
UDPUDP datagramApp responseICMP UnreachableSlow; finds DNS/SNMP
💡 Tip: SYN scan (nmap -sS) is the most commonly used scan in practice. It only completes the first half of the handshake—fast and leaves no application-layer logs. But it requires root/admin privileges since it constructs raw packets.

Port States

StateMeaningCause
openListeningService running
closedReachable, no serviceService stopped
filteredCannot determineFirewall DROP

Essential Commands

# Quick scan of common ports (SYN scan, needs root)
sudo nmap -sS -T4 --top-ports 1000 target_ip

# Full port scan (takes longer)
sudo nmap -sS -p- target_ip

# Service version detection
sudo nmap -sV -p 22,80,443,3306 target_ip

# OS fingerprinting
sudo nmap -O target_ip

# UDP scan (common UDP services)
sudo nmap -sU --top-ports 100 target_ip

# Comprehensive scan (version + scripts + OS detection)
sudo nmap -A -T4 target_ip

High-Risk Ports

PortServiceRiskFix
22SSHBrute forceKey auth + fail2ban
3389RDPBrute force + exploitsVPN only
3306MySQLUnauthorized accessBind 127.0.0.1
6379RedisNo auth → RCESet password + localhost
9200ElasticsearchData exposureDon't expose + auth
27017MongoDBUnauthorized accessEnable auth + IP restrict
⚠️ Warning: Scanning servers you don't own may violate applicable laws. Always scan only targets you are authorized to test.

🔒 Server Port Security Checklist:

  • Least exposure: Only open required ports
  • Never expose databases publicly
  • Management via VPN
  • Monthly self-audits with nmap
  • Use ipinfo.im Port Scanner for quick checks