Ports and Protocols: Understanding Network Communication
Learn about network ports, their numbering system, common protocols at each layer, how services use ports, and security implications.
Mapping Services with Network Ports
Every open port on a target is a potential entry point. Port scanning is one of the first things you will do in any security assessment, and understanding the port numbering system, common service mappings, and how firewalls filter ports is fundamental. This guide gives you a practical reference for working with ports in security contexts.
Prerequisites
Basic understanding of IP addressing and TCP/IP. Familiarity with the OSI model is helpful.
Port Number Ranges
Well-Known Ports (0-1023)
Reserved for system services. Require root/admin privileges. Assigned by IANA to core internet services.
Registered Ports (1024-49151)
Can be registered with IANA for specific applications. Used by enterprise and proprietary software.
Dynamic/Private Ports (49152-65535)
Ephemeral ports dynamically assigned to client applications for temporary communication. Your browser uses a random ephemeral port when connecting to a web server.
Common Protocols and Ports
Web
| Port | Protocol | Transport | Description |
|---|---|---|---|
| 80 | HTTP | TCP | Unencrypted web |
| 443 | HTTPS | TCP | Encrypted web (TLS) |
| 8080 | HTTP Alt | TCP | Alternate HTTP (proxies) |
| 8443 | HTTPS Alt | TCP | Alternate HTTPS |
Remote Access
| Port | Protocol | Transport | Description |
|---|---|---|---|
| 22 | SSH | TCP | Secure remote administration |
| 23 | Telnet | TCP | Unencrypted remote terminal (obsolete) |
| 3389 | RDP | TCP | Windows Remote Desktop |
| 5900 | VNC | TCP | Remote desktop (cross-platform) |
| Port | Protocol | Transport | Description |
|---|---|---|---|
| 25 | SMTP | TCP | Outgoing mail |
| 587 | SMTP Sub | TCP | SMTP with authentication |
| 110 | POP3 | TCP | Incoming mail |
| 143 | IMAP | TCP | Incoming mail (with folders) |
| 993 | IMAPS | TCP | IMAP over SSL |
File Transfer
| Port | Protocol | Transport | Description |
|---|---|---|---|
| 21 | FTP | TCP | File Transfer Protocol (control) |
| 20 | FTP | TCP | FTP data channel |
| 445 | SMB | TCP | Windows file sharing |
| 2049 | NFS | TCP/UDP | Network File System |
Databases
| Port | Protocol | Transport | Description |
|---|---|---|---|
| 3306 | MySQL | TCP | MySQL database |
| 5432 | PostgreSQL | TCP | PostgreSQL |
| 1433 | MSSQL | TCP | Microsoft SQL Server |
| 27017 | MongoDB | TCP | MongoDB |
| 6379 | Redis | TCP | Redis key-value store |
Infrastructure
| Port | Protocol | Transport | Description |
|---|---|---|---|
| 53 | DNS | TCP/UDP | Domain Name System |
| 67/68 | DHCP | UDP | IP address assignment |
| 161 | SNMP | UDP | Network monitoring |
| 123 | NTP | UDP | Time synchronization |
How Ports Work in Practice
Client-Server Communication
When browsing a website: browser picks ephemeral port (e.g., 54321), connects to server's port 443, server responds to ephemeral port. Connection uniquely identified by: (source IP, source port, dest IP, dest port).
Service Binding
ss -tulpn # Shows listening services and their ports
# tcp LISTEN 0.0.0.0:22 # SSH
# tcp LISTEN 0.0.0.0:80 # HTTP (nginx)
# tcp LISTEN 0.0.0.0:443 # HTTPS (nginx)
Port Scanning
nmap -sS 192.168.1.1 # Default scan
nmap -p 22,80,443,3306 192.168.1.1 # Specific ports
nmap -p- 192.168.1.1 # All 65535 ports
nmap -sV 192.168.1.1 # Service version detection
nmap --top-ports 1000 192.168.1.1 # Most common ports
Port Security
Every open port is a potential entry point. Each port has a service that may have vulnerabilities.
Firewall best practice: Allow only necessary ports.
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT # SSH only
sudo iptables -A INPUT -j DROP # Default deny
Port Knocking: Hide services by requiring connection attempts to a sequence of closed ports before opening the real port.
Service-Specific Security: SSH (disable root, use keys). MySQL (bind to localhost). HTTP (redirect to HTTPS). RDP (use VPN + NLA).
Real-World Examples
Suspicious Ports: Unexpected ports like 4444 (Metasploit), 31337 (Back Orifice), or 6667 (IRC/botnet C2) may indicate compromise.
Port Forwarding: ssh -L 8080:internal:80 user@gateway forwards local port 8080 to internal web server through SSH.
Common Mistakes
Using well-known ports for custom services. Assuming a port guarantees a specific service — always verify with version detection. Forgetting UDP ports (DNS, SNMP, DHCP).
Best Practices
Default deny firewall policy. Use version detection to confirm services. Monitor for unexpected open ports. Segment networks. Regular infrastructure port scanning.
Related Tools
nmap — Port scanner. netcat — Manual port testing. ss/netstat — Local listening ports. lsof — Processes using ports. masscan — High-speed scanning.
Related Articles
Summary
Ports (0-65535) direct traffic to services on a host. Well-known (0-1023) for core services, registered (1024-49151) for applications, dynamic (49152-65535) for ephemeral client connections. Every open port is a potential attack vector. Understanding ports is essential for network admin, firewall config, and security assessment.
Knowledge Check
Frequently Asked Questions
Continue Learning
OSI Model Explained: The Seven Layers of Networking
Master the OSI model's seven layers, understand how each layer functions, learn real-world protocol examples, and use the model for troubleshooting.
Networking · BeginnerNetworking Basics: Understanding TCP/IP, DNS, and Network Protocols
Learn the fundamentals of computer networking including the OSI model, TCP/IP protocol suite, IP addressing, subnetting, DNS, and network security essentials.
Networking · IntermediateDNS Explained: How the Domain Name System Works and Its Security
An in-depth exploration of DNS architecture, resolution process, record types, caching, security threats, and privacy protocols like DoH and DoT.
Networking · IntermediateInternet Infrastructure: DNS, WHOIS, and Domain Systems
Understand the core infrastructure of the internet including DNS hierarchy, WHOIS databases, Regional Internet Registries, and how domain names are managed globally.
Related Security Tools
Netcat
Learn how to use Netcat (nc) in Kali Linux to open a TCP or UDP connection, check a port, and see what a service sends back. Follow the examples to send your first message, inspect HTTP and SMTP responses, and transfer a test file without exposing sensitive data.
Information GatheringNmap
Learn how to use Nmap, the free open-source network scanner: run your first port scan, discover live hosts, detect services and operating systems, and check for vulnerabilities with NSE scripts — a beginner tutorial for Kali Linux.
Information GatheringMasscan
Masscan is an internet-scale port scanner. It can scan the entire Internet in under 6 minutes, transmitting up to 10 million packets per second utilizing asynchronous transmit setups.
Stress Testinghping3
hping3 is a command-line network tool for crafting, sending, and analyzing custom TCP/IP packets. Built for firewall testing, port scanning, OS fingerprinting, path MTU discovery, and authorized stress testing, it gives you control over nearly every field of the TCP, UDP, ICMP, and raw IP headers — the flags, sequence numbers, window size, TTL, fragmentation, and payload — and then shows you exactly how the target answers. Where Nmap runs predefined scan types, hping3 is the packet workbench you reach for when the question is "what does the firewall do with THIS exact packet?" It runs on raw sockets (so it needs root), supports scan and listen modes, and includes a Tcl scripting engine for automating protocol experiments in a lab.