Every time you browse a website, send an email, or SSH into a server, your computer is using a port number to tell the destination machine exactly which service it wants to talk to. IP addresses get your data to the right machine; port numbers get it to the right application on that machine. This article explains ports from the ground up, walks through the most important well-known services, and shows practical examples of inspecting and managing ports on Linux and Cisco devices.
What Is a Port Number?
A port is a 16-bit number (0–65535) used by the Transport Layer (TCP or UDP) to distinguish between different services or connections running on the same IP address. Think of an IP address as a building’s street address, and a port number as the specific apartment number inside that building.
A network connection is fully identified by a socket, made up of:
(Source IP, Source Port, Destination IP, Destination Port, Protocol)
This 5-tuple is what allows a single server to handle thousands of simultaneous connections without confusing them.
graph TD
Client[Client 203.0.113.5:52344] -->|TCP SYN to port 443| Server[Web Server 198.51.100.10:443]
Server -->|TCP SYN-ACK| Client
Client -->|TCP ACK| Server
Client -->|HTTPS Request| Server
Port Ranges
| Range | Name | Description |
|---|---|---|
| 0–1023 | Well-Known Ports | Reserved for standard services (HTTP, SSH, DNS). Require root/admin privileges to bind on most OSes. |
| 1024–49151 | Registered Ports | Assigned to specific applications by IANA but not privileged. |
| 49152–65535 | Dynamic/Private Ports | Used for ephemeral, client-side connections. |
Common Internet Services and Their Ports
| Port | Protocol | Service | Description |
|---|---|---|---|
| 20/21 | TCP | FTP | File Transfer Protocol (data/control) |
| 22 | TCP | SSH | Secure Shell for remote login |
| 23 | TCP | Telnet | Unencrypted remote login (legacy) |
| 25 | TCP | SMTP | Sending email between mail servers |
| 53 | TCP/UDP | DNS | Domain Name resolution |
| 67/68 | UDP | DHCP | Dynamic IP address assignment |
| 69 | UDP | TFTP | Trivial File Transfer, used for firmware/config loads |
| 80 | TCP | HTTP | Unencrypted web traffic |
| 110 | TCP | POP3 | Retrieving email |
| 123 | UDP | NTP | Network Time Protocol |
| 143 | TCP | IMAP | Retrieving/syncing email |
| 161/162 | UDP | SNMP | Network device monitoring |
| 179 | TCP | BGP | Border Gateway Protocol (internet routing) |
| 389 | TCP | LDAP | Directory services |
| 443 | TCP | HTTPS | Encrypted web traffic |
| 445 | TCP | SMB | Windows file sharing |
| 465/587 | TCP | SMTPS/Submission | Encrypted email submission |
| 514 | UDP | Syslog | Centralized logging |
| 993 | TCP | IMAPS | Encrypted IMAP |
| 995 | TCP | POP3S | Encrypted POP3 |
| 3306 | TCP | MySQL | Database access |
| 3389 | TCP | RDP | Windows Remote Desktop |
| 5432 | TCP | PostgreSQL | Database access |
TCP vs UDP Ports
The same port number can be used independently by TCP and UDP, since they are separate protocols with separate port spaces. DNS is a good example — it primarily uses UDP port 53 for quick lookups but falls back to TCP port 53 for larger responses like zone transfers.
| Feature | TCP | UDP |
|---|---|---|
| Connection | Connection-oriented (3-way handshake) | Connectionless |
| Reliability | Guaranteed delivery, retransmission | Best-effort, no guarantee |
| Ordering | In-order delivery | No ordering guarantee |
| Overhead | Higher | Lower |
| Typical Use | Web, email, file transfer | DNS queries, streaming, VoIP |
Inspecting Ports on Linux
Viewing Listening Ports
# Modern method (recommended)
sudo ss -tulnp
# Legacy method (still widely used)
sudo netstat -tulnp
Example output:
Netid State Local Address:Port Process
tcp LISTEN 0.0.0.0:22 sshd
tcp LISTEN 0.0.0.0:80 nginx
tcp LISTEN 127.0.0.1:3306 mysqld
-tTCP,-uUDP,-llistening sockets only,-nnumeric (don’t resolve names),-pshow the owning process.
Scanning Open Ports on a Remote Host
# Using nmap to scan the most common 1000 ports
nmap 192.168.1.10
# Scanning a specific range
nmap -p 1-1000 192.168.1.10
# Version detection
nmap -sV 192.168.1.10
Opening a Port in the Firewall (UFW example)
sudo ufw allow 443/tcp
sudo ufw allow 53/udp
sudo ufw status verbose
Opening a Port with firewalld (RHEL/CentOS)
sudo firewall-cmd --permanent --add-port=8080/tcp
sudo firewall-cmd --reload
sudo firewall-cmd --list-ports
Managing Ports on Cisco Devices
Cisco routers and switches use access control lists (ACLs) to permit or deny traffic based on port numbers.
Router(config)# access-list 101 permit tcp any any eq 443
Router(config)# access-list 101 permit tcp any any eq 80
Router(config)# access-list 101 deny tcp any any eq 23
Router(config)# access-list 101 permit ip any any
Router(config)# interface gigabitEthernet 0/0
Router(config-if)# ip access-group 101 in
This example permits HTTPS and HTTP, explicitly blocks Telnet (port 23) as a security best practice, and allows all other IP traffic.
Checking Ports Programmatically with Python
import socket
def scan_port(host, port, timeout=1):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
sock.settimeout(timeout)
result = sock.connect_ex((host, port))
return result == 0
host = "192.168.1.10"
common_ports = {21: "FTP", 22: "SSH", 80: "HTTP", 443: "HTTPS", 3306: "MySQL"}
for port, name in common_ports.items():
status = "OPEN" if scan_port(host, port) else "CLOSED"
print(f"Port {port} ({name}): {status}")
This kind of script is useful for quick service-availability checks, but for real audits, dedicated tools like nmap are far more capable and efficient.
Best Practices
- Close or firewall any port not actively used by a required service.
- Never expose Telnet (23), FTP (21), or unencrypted management ports to the internet — use SSH, SFTP, and HTTPS equivalents instead.
- Use non-standard ports only as a minor deterrent, never as your primary security control (“security through obscurity” is not real security).
- Log connection attempts to sensitive ports (SSH, RDP) and use fail2ban or equivalent to block brute-force attempts.
- Regularly audit listening ports on servers with
ss -tulnp. - Segment services onto separate VLANs/subnets so a compromised host on one port doesn’t expose everything else.
Troubleshooting
| Problem | Diagnostic Command | What to Check |
|---|---|---|
| Can’t connect to a service | telnet host port or nc -zv host port | Is the port open? Firewall blocking? |
| Service not starting | sudo ss -tulnp | grep <port> | Is another process already bound to that port? |
| Port shows open but app doesn’t respond | curl -v http://host:port | Application-layer issue, not a port issue |
| Intermittent connection failures | mtr host | Packet loss along the path |
Further Reading
- IANA Service Name and Port Number Registry
- RFC 793 — Transmission Control Protocol
- RFC 768 — User Datagram Protocol
- Nmap Official Documentation
- Cisco ACL Configuration Guide
Conclusion
Port numbers are the addressing system that lets a single IP handle dozens of simultaneous services. Understanding well-known ports, how to inspect them on Linux, and how to control them with ACLs and firewalls is essential groundwork for anything from basic troubleshooting to serious network security work.