Network Port Security & Hardening: Well-Known Ports, Transport Protocols & Firewalls
A comprehensive guide to Layer-4 port multiplexing: analyze well-known TCP/UDP port ranges, understand common attack vectors on open ports, and implement firewall rules using UFW and iptables.
Network Port Reference Directory
Search common TCP & UDP port assignments, protocol descriptions, and security vulnerability profiles.
The Role of Ports in Transport Layer Multiplexing
A single server host connected to the internet has only one public IP address, yet it simultaneously serves web pages, accepts SSH terminal logins, synchronizes system clocks via NTP, and answers DNS queries.
This concurrency is made possible by Layer-4 Port Multiplexing. Both TCP (Transmission Control Protocol) and UDP (User Datagram Protocol) headers include 16-bit source and destination port fields. A 16-bit integer allows for:
$$\text{Total Ports} = 2^{16} = 65,536 \text{ ports (0 to 65535)}$$
A unique network socket connection is defined by the 5-tuple: 1. Source IP 2. Source Port 3. Destination IP 4. Destination Port 5. Transport Protocol (TCP or UDP)
IANA Port Classifications
The Internet Assigned Numbers Authority (IANA) partitions the 65,536 port spectrum into three standardized ranges:
| Tier | Port Range | Administrative Rules | Common Examples |
|---|---|---|---|
| Well-Known Ports | 0 – 1023 | Historically reserved for root-privileged core internet protocols. | HTTP (80), HTTPS (443), SSH (22), DNS (53), NTP (123). |
| Registered Ports | 1024 – 49151 | Assigned by IANA to specific commercial applications, databases, and microservices. | MySQL (3306), Redis (6379), PostgreSQL (5432), Docker (2375). |
| Dynamic / Ephemeral | 49152 – 65535 | Automatically allocated by client OS kernels for outbound socket handshakes. | Outbound browser client sockets. |
Top Vulnerable Ports & Recommended Hardening
Automated threat actors continuously scan the public IPv4 internet using fast port scanners like Masscan and ZMap. Certain ports should never be exposed directly to the public internet:
1. Database Services (MySQL 3306, PostgreSQL 5432, Redis 6379, MongoDB 27017)
127.0.0.1) or private VPC subnets. Access databases remotely only through encrypted SSH tunnels or WireGuard VPNs.2. Remote Administration (SSH 22, RDP 3389, Telnet 23)
/etc/ssh/sshd_config (PasswordAuthentication no), enforce Ed25519 public key authentication, configure Fail2ban to ban aggressive IPs, or migrate behind a Zero Trust bastion like Cloudflare Tunnel.3. Cleartext File Transfer (FTP 20/21)
Configuring Host Firewalls: UFW & Iptables
On production Linux servers, a stateful firewall acts as the first line of perimeter defense by dropping unsolicited ingress packets before they reach running software daemons.
Ubuntu / Debian: Hardening with UFW (Uncomplicated Firewall)
1. Set default policies: deny all incoming, allow all outgoing
sudo ufw default deny incoming
sudo ufw default allow outgoing
2. Allow SSH (Port 22) to prevent locking yourself out
sudo ufw allow 22/tcp
3. Allow Web Traffic (Ports 80 & 443)
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
4. Allow Database access ONLY from a trusted backend subnet (e.g., 10.0.1.0/24)
sudo ufw allow from 10.0.1.0/24 to any port 5432 proto tcp
5. Enable the firewall and check status
sudo ufw enable
sudo ufw status verbose
Quick Reference & Port Directory
Need to look up port numbers, inspect transport layer protocols, or verify security vulnerability profiles? Explore our free Network Port Reference Directory for real-time search across hundreds of registered protocols.
Editorial Integrity & Peer Review
All technical guides on MicroTools are independently authored and peer-reviewed by software and infrastructure professionals. Content is updated periodically to ensure compliance with the latest IETF RFC specifications, IEEE standards, and cloud provider architectural recommendations.