CYBER SECURITY • NETWORKING AND INTERNET SECURITY

Ports & Common Protocols — Explain ports and common protocols (TCP/UDP, DNS, DHCP, HTTP/S, SSH) and why they matter for security

Understanding how network ports and protocols enable—and expose—digital communication is foundational to defensive security.

Historical Context & Motivation

The modern internet is built upon decades of protocol engineering, each layer addressing a specific communication challenge. In the earliest days of ARPANET, researchers needed a way for multiple applications on a single host to share a network connection simultaneously. The concept of a port number emerged as a logical addressing mechanism to multiplex traffic, allowing a single machine to host a web server, an email daemon, and a file transfer service all at once. Without ports, every host could only sustain a single network conversation at a time—a crippling limitation for general-purpose computing.

Protocols evolved in tandem with these addressing schemes. Early protocols like NCP (Network Control Protocol) were replaced by the more robust TCP/IP suite in 1983, a transition known as "flag day." As the internet grew from a research curiosity into critical infrastructure, each new protocol—DNS for name resolution, HTTP for the web, SSH for secure remote administration—introduced both capabilities and attack surfaces. Understanding the historical trajectory of these protocols illuminates why certain design decisions persist and where security vulnerabilities originate.

1969
ARPANET & NCP
The first ARPANET nodes come online using the Network Control Protocol, which lacked port-like multiplexing and offered no built-in security. Each host-to-host connection required manual coordination.
1981
TCP/UDP Standardized (RFC 793 & 768)
The Transmission Control Protocol and User Datagram Protocol are formally specified, introducing 16-bit port numbers (0–65535) for application-layer multiplexing. TCP provides reliable, ordered delivery; UDP trades reliability for speed.
1983
DNS Introduced (RFC 882/883)
The Domain Name System replaces the monolithic HOSTS.TXT file, creating a distributed hierarchical namespace. DNS operates primarily over UDP port 53, enabling scalable hostname resolution.
1995
HTTP/1.0 & SSL/TLS Emerge
HTTP/1.0 is formalized (RFC 1945) and Netscape introduces SSL, eventually standardized as TLS. HTTP uses port 80 while HTTPS binds to port 443, adding encryption to web traffic.
1999
SSH Replaces Telnet and rlogin
OpenSSH is released, providing encrypted remote shell access on port 22. It rapidly replaces the plaintext Telnet (port 23) and rlogin protocols, dramatically improving remote administration security.

The recurring theme across these milestones is a tension between functionality and security. Each protocol was designed to solve a communication problem—often in a trusted academic environment—and security was bolted on afterward. This historical pattern is precisely why understanding ports and protocols is essential for any security professional: the attack surface of a networked system is directly proportional to the number of open ports and the security posture of the protocols behind them.

Core Principles & Definitions

Before diving into individual protocols, it is critical to establish a precise vocabulary. A port is a 16-bit unsigned integer (ranging from 0 to 65,535) that serves as an endpoint identifier for network communication on a host. Combined with an IP address, a port forms a socket—a unique tuple that the operating system kernel uses to route incoming packets to the correct process. A protocol is a formal specification defining the syntax, semantics, and synchronization rules for data exchange between network entities. Protocols operate at various layers of the OSI or TCP/IP model, and a given port is typically associated with a specific application-layer protocol by convention.

1

Port Ranges

Ports are divided into three ranges: well-known ports (0–1023) assigned by IANA to standard services, registered ports (1024–49151) for vendor applications, and dynamic/ephemeral ports (49152–65535) used by client-side connections.
2

TCP: Reliable, Ordered Delivery

The Transmission Control Protocol establishes a connection via a three-way handshake (SYN → SYN-ACK → ACK), provides flow control, congestion avoidance, and guarantees in-order delivery through sequence numbers and acknowledgments.
3

UDP: Fast, Connectionless

The User Datagram Protocol is a stateless, best-effort transport. It adds only source port, destination port, length, and checksum fields to IP datagrams. Ideal for real-time applications (VoIP, DNS lookups, gaming) where retransmission latency is unacceptable.
4

Principle of Least Privilege

From a security standpoint, every open port is a potential entry point. The principle of least privilege dictates that only ports required for operational needs should be open. Firewall rules, access control lists, and network segmentation enforce this principle at the network layer.
5

Defense in Depth

No single protocol or firewall rule provides complete security. Defense in depth layers protections—encryption (TLS/SSH), authentication, intrusion detection, and logging—across all exposed ports and services to create redundant security controls.
KEY TAKEAWAY
Think of an IP address as the street address of an apartment building and ports as individual apartment numbers. A letter (packet) addressed to 192.168.1.10:443 is delivered to the specific "apartment" where the HTTPS web server lives. If an apartment door is left unlocked (an open port with a vulnerable service), an intruder can walk in. Security means locking every door you are not using and installing deadbolts (encryption, authentication) on the ones you leave open.

Visual Explanation — Port Architecture and the TCP/IP Stack

The TCP/IP protocol stack maps application-layer protocols to transport-layer ports. Each application (HTTP, DNS, SSH, etc.) binds to a specific well-known port and selects either TCP (reliable) or UDP (fast) as its transport. Packets are then encapsulated through the network, data link, and physical layers for transmission.

The diagram above illustrates how the layered architecture of TCP/IP creates an abstraction hierarchy. At the top, application-layer protocols such as HTTP, DNS, and SSH define the semantics of communication—what data means and how it is structured. These protocols bind to well-known ports that the transport layer (TCP or UDP) uses to demultiplex incoming traffic. The critical security insight is that vulnerabilities can exist at any layer: a buffer overflow in an application on port 80 (Layer 7), a TCP sequence prediction attack (Layer 4), IP spoofing (Layer 3), or ARP poisoning (Layer 2). Effective security requires awareness of the entire stack, not just the application layer.

How It Works — Protocol Mechanics Deep Dive

TCP Three-Way Handshake

TCP's reliability begins with its connection establishment procedure, the three-way handshake. The client sends a SYN segment with an initial sequence number (ISN), the server responds with a SYN-ACK containing its own ISN and an acknowledgment of the client's ISN + 1, and the client completes the handshake with an ACK. This mechanism synchronizes sequence numbers and establishes state on both endpoints. From a security perspective, the handshake is vulnerable to SYN flood attacks, where an attacker sends massive volumes of SYN segments with spoofed source addresses, exhausting the server's connection table. Mitigations include SYN cookies (RFC 4987), rate limiting, and firewall-based half-open connection tracking.

SOCKET IDENTIFICATION
Socket = (IP_src, Port_src, IP_dst, Port_dst, Protocol)
A socket is uniquely identified by a 5-tuple: source IP, source port, destination IP, destination port, and protocol (TCP or UDP). This allows a single server IP to handle thousands of concurrent connections on the same destination port by differentiating on source IP and ephemeral source port.

UDP Simplicity and Implications

UDP's minimal header—only 8 bytes comprising source port, destination port, length, and checksum—makes it exceptionally lightweight. There is no handshake, no connection state, and no retransmission logic. This design is ideal for DNS queries (where a single request-response pair suffices) and real-time media streams (where a late packet is worse than a lost one). However, the lack of a handshake makes UDP susceptible to amplification attacks. An attacker can spoof the victim's IP address in a DNS query to an open resolver; the resolver sends its (much larger) response to the victim. Amplification factors for DNS can exceed 50×, making UDP-based services a favorite vector for distributed denial-of-service (DDoS) attacks.

AMPLIFICATION FACTOR
AF = Response_size / Request_size
The amplification factor (AF) quantifies the ratio of the response payload to the request payload. For DNS, a 60-byte query can produce a 3,000+ byte response (AF ≈ 50). For NTP monlist, AF can reach 556. Higher AF values make the protocol more attractive to DDoS attackers.

DNS Resolution Process

The Domain Name System translates human-readable domain names (e.g., example.com) into IP addresses through a distributed, hierarchical lookup. A client's stub resolver queries a recursive resolver, which in turn queries root name servers, TLD (top-level domain) servers, and authoritative name servers in sequence, caching results according to TTL (time-to-live) values. DNS typically uses UDP port 53 for standard queries but falls back to TCP port 53 for zone transfers and responses exceeding 512 bytes (or 4,096 bytes with EDNS0). Security threats include DNS cache poisoning (injecting fraudulent records into a resolver's cache), DNS tunneling (encoding arbitrary data in DNS queries to exfiltrate information), and DNS hijacking. DNSSEC (DNS Security Extensions) adds cryptographic signatures to DNS records to verify authenticity.

DHCP Lease Process

The Dynamic Host Configuration Protocol automates IP address assignment through a four-step broadcast exchange known as DORA: Discover (client broadcasts on UDP port 67), Offer (server responds on UDP port 68), Request (client selects an offer), and Acknowledge (server confirms the lease). Because DHCP relies on broadcast and has no built-in authentication, it is vulnerable to rogue DHCP server attacks (an attacker provides malicious gateway/DNS settings) and DHCP starvation (exhausting the address pool with forged requests). DHCP snooping on managed switches mitigates these threats by filtering unauthorized DHCP responses.

Detailed Protocol-Port Mapping & Security Implications

This reference chart maps each major protocol to its assigned port(s), transport layer, purpose, and encryption status. Protocols marked with ✗ NO transmit data in cleartext and are inherently vulnerable to eavesdropping. Protocols marked with ✓ YES provide built-in encryption. Note that DNS can optionally be encrypted via DNS-over-HTTPS (DoH) or DNS-over-TLS (DoT).

Several critical observations emerge from the protocol table above. First, the distinction between encrypted and unencrypted protocols has profound security implications: any credentials or sensitive data sent over HTTP, Telnet, or FTP can be captured by a network sniffer in plaintext. This is why security best practice mandates HTTPS for all web traffic (not just login pages), SSH instead of Telnet, and SFTP or SCP instead of FTP. Second, protocols like DNS and DHCP, which are fundamental to network bootstrapping, have historically lacked encryption and authentication—making them attractive targets for man-in-the-middle and spoofing attacks.

HTTP vs. HTTPS — The TLS Layer

HTTPS is not a separate protocol but rather HTTP layered over Transport Layer Security (TLS). During the TLS handshake, the client and server negotiate a cipher suite, the server presents a digital certificate (validated against a trusted Certificate Authority chain), and a symmetric session key is derived using asymmetric key exchange (typically ECDHE). All subsequent HTTP traffic is encrypted, ensuring confidentiality, integrity, and server authentication. Modern browsers flag HTTP sites as "Not Secure," and organizations should enforce HTTPS via HTTP Strict Transport Security (HSTS) headers to prevent protocol downgrade attacks.

SSH — Secure Shell Architecture

SSH provides three core services: encrypted remote shell access, secure file transfer (SFTP/SCP), and port forwarding (tunneling). The protocol uses a client-server model on TCP port 22. During connection, SSH negotiates encryption algorithms, performs host key verification (protecting against man-in-the-middle attacks), and authenticates the user via password, public key, or certificate-based methods. Public key authentication is strongly preferred over passwords because it eliminates the risk of brute-force attacks against weak passwords. SSH's port forwarding capability also makes it a powerful tool for securely accessing services behind firewalls, though this same capability can be exploited for unauthorized tunneling.

Worked Example — Analyzing a Network Scan and Hardening a Server

Consider this scenario: you are a security analyst who has been asked to audit a newly provisioned Linux web server. You run an Nmap scan and discover the following open ports: 22 (SSH), 23 (Telnet), 25 (SMTP), 53 (DNS), 80 (HTTP), 443 (HTTPS), and 3306 (MySQL). Your task is to identify security risks and recommend remediation actions.

Server Hardening Based on Port Analysis
1
Step 1 — Inventory Open Ports and Associated ServicesList each open port and the service behind it. Port 22 runs OpenSSH, port 23 runs Telnet, port 25 runs Postfix SMTP, port 53 runs BIND DNS, port 80 runs Apache HTTP, port 443 runs Apache HTTPS, and port 3306 runs MySQL. Determine which services are required for the server's role as a web server.
Required: 22 (SSH for admin), 80 (HTTP → redirect to HTTPS), 443 (HTTPS). Unnecessary: 23, 25, 53, 3306 (externally).
2
Step 2 — Identify Critical VulnerabilitiesPort 23 (Telnet) is a severe risk because it transmits credentials in cleartext. Port 3306 (MySQL) should never be exposed to the internet—it allows direct database connections. Port 25 (SMTP) is only needed if the server sends email, but open SMTP relays are exploited for spam. Port 53 (DNS) is unnecessary if the server is not an authoritative DNS server.
Telnet on port 23 = CRITICAL: plaintext authentication, must be disabled immediately
3
Step 3 — Apply Firewall Rules (iptables / nftables)Configure the host-based firewall to drop all inbound traffic by default (default-deny policy), then explicitly allow only ports 22, 80, and 443. For port 22, restrict source IPs to your organization's administrative subnet (e.g., iptables -A INPUT -p tcp --dport 22 -s 10.0.1.0/24 -j ACCEPT). Bind MySQL to 127.0.0.1 (localhost only) to prevent external access.
Firewall reduces external attack surface from 7 ports to 3 (SSH restricted, HTTP, HTTPS).
4
Step 4 — Disable Unnecessary ServicesStop and disable Telnet: systemctl stop telnet.socket && systemctl disable telnet.socket. Uninstall the Telnet server package entirely. If SMTP and DNS are not needed, stop Postfix and BIND and remove them from startup. This follows the principle of attack surface reduction: services that do not run cannot be exploited.
Attack surface reduced by ~57% (4 unnecessary services eliminated)
5
Step 5 — Harden Remaining ServicesFor SSH: disable root login (PermitRootLogin no in sshd_config), enforce public key authentication (PasswordAuthentication no), and consider changing the SSH port to a non-standard value (security through obscurity, not a substitute for real controls but reduces automated scanning noise). For HTTP: configure a 301 redirect from port 80 to port 443 to enforce HTTPS. Enable HSTS with a max-age of at least one year. Install and configure a valid TLS certificate (e.g., via Let's Encrypt).
Final state: 3 ports open, all hardened — SSH (key-only, IP-restricted), HTTP (redirect only), HTTPS (TLS 1.3, HSTS)

Protocol Security Comparison — Strengths and Vulnerabilities

Protocol security comparison matrix
ProtocolSecurity StrengthsKnown VulnerabilitiesMitigations
TCPStateful connections enable firewall tracking; sequence numbers add basic integritySYN floods, TCP reset attacks, session hijacking via sequence number predictionSYN cookies, randomized ISNs, stateful firewalls, TCP wrappers
UDPMinimal attack surface on the protocol itself; no connection state to exhaustAmplification/reflection DDoS, UDP flood, no built-in authenticationRate limiting, BCP38 ingress filtering, disabling open resolvers
DNSDistributed architecture provides redundancy; caching improves performanceCache poisoning, DNS tunneling, zone transfer leaks, DDoS amplificationDNSSEC, DoH/DoT, restricted zone transfers, response rate limiting (RRL)
DHCPAutomates network configuration; reduces human error in IP managementRogue DHCP servers, DHCP starvation, no authenticationDHCP snooping, port security, 802.1X network access control
HTTPSimple, well-understood, massive ecosystem of security toolsPlaintext transmission, session hijacking, MITM, header injectionUpgrade to HTTPS, HSTS preloading, Content Security Policy headers
HTTPSEnd-to-end encryption, server authentication, integrity verificationCertificate misconfiguration, protocol downgrade attacks, weak cipher suitesCertificate Transparency, HSTS, TLS 1.3 enforcement, OCSP stapling
SSHStrong encryption, host key verification, flexible authentication methodsBrute-force password attacks, key management issues, CVEs in implementationsKey-based auth, fail2ban, jump hosts/bastion servers, regular patching
KEY TAKEAWAY
Think of protocols as different types of mail service. HTTP is like a postcard—anyone who handles it can read the message. HTTPS is a sealed, tamper-evident envelope with a verified return address. SSH is a diplomatic pouch with an armed courier. DNS is the postal addressing system itself—if someone corrupts the address book, your sealed envelope goes to the wrong recipient. The security of your communication depends not just on the envelope (encryption) but on the integrity of every system in the delivery chain.

Connection to Advanced Theory — Beyond Basic Ports and Protocols

The foundational understanding of ports and protocols presented in this lesson connects directly to several advanced security domains. Network segmentation and zero-trust architectures extend the principle of least privilege from individual ports to entire network zones, requiring authentication and authorization for every connection regardless of source. Deep packet inspection (DPI) goes beyond port-based filtering to analyze the actual payload content, detecting anomalies like encrypted C2 (command-and-control) traffic disguised as HTTPS or DNS tunneling on port 53. Modern firewalls operate as application-layer gateways, classifying traffic by protocol behavior rather than port number alone.

From foundational concepts to advanced security practice
Foundational ConceptAdvanced Extension
Port-based firewall rules (allow/deny by port number)Next-generation firewalls (NGFW) with application-aware filtering, DPI, and behavioral analysis
DNS resolution over UDP port 53DNS-over-HTTPS (DoH, port 443), DNS-over-TLS (DoT, port 853), DNS-over-QUIC, encrypted client hello (ECH)
TLS for HTTPS on port 443Mutual TLS (mTLS) for service mesh authentication, certificate pinning, post-quantum cryptographic algorithms
SSH key-based authenticationSSH certificate authorities, hardware security keys (FIDO2/U2F), short-lived certificates, zero-trust BeyondCorp models
Nmap port scanning for reconnaissanceAutomated vulnerability scanning (Nessus, OpenVAS), continuous attack surface monitoring, OSINT-based external reconnaissance

An important forward-looking trend is the convergence of encrypted protocols onto a small number of ports—primarily TCP 443. HTTPS, HTTP/2, HTTP/3 (QUIC over UDP 443), DoH, and even some VPN protocols all use port 443, partly because firewalls rarely block it. This trend complicates traditional port-based security models and drives adoption of traffic analysis, behavioral detection, and endpoint-centric security models that operate independently of port numbers. Understanding this evolution is essential as you advance into courses on intrusion detection, incident response, and security architecture.

Practice Problems

PROBLEM 1CONCEPTUAL
Explain why a single web server with IP address 203.0.113.5 can simultaneously serve thousands of HTTPS clients, all connecting to the same destination port 443. What mechanism allows the operating system to differentiate these connections?
PROBLEM 2BASIC CALCULATION
A port number is represented by a 16-bit unsigned integer. Calculate the total number of possible port values. If the well-known range occupies ports 0–1023, the registered range occupies 1024–49151, and the dynamic range occupies 49152–65535, what percentage of the total port space does each range represent?
PROBLEM 3INTERMEDIATE
An Nmap scan of a corporate file server reveals the following open ports: 21 (FTP), 22 (SSH), 80 (HTTP), 139 (NetBIOS), 445 (SMB), 3389 (RDP). The server's intended role is to serve files exclusively to internal users via SMB. Identify which ports represent unnecessary risk, and propose a specific remediation plan for each.
PROBLEM 4APPLIED
A security operations center (SOC) analyst notices an unusual spike in outbound DNS traffic (UDP port 53) from a single workstation, averaging 500 queries per minute to an external DNS server, with unusually large TXT record responses (averaging 4,000 bytes each). Normal baseline for this workstation is 5 queries per minute. Describe what attack technique this likely represents, explain how it works, calculate the approximate data exfiltration rate in KB per minute, and propose detection and prevention measures.
PROBLEM 5CRITICAL THINKING
Modern web applications increasingly tunnel all traffic over port 443 (HTTPS, WebSockets, gRPC, HTTP/3 via QUIC). DNS-over-HTTPS further collapses DNS onto port 443. Analyze the implications of this convergence for traditional port-based firewall security models. Is port-based filtering becoming obsolete? Argue both sides and propose a security architecture that remains effective in a port-443-converged world.

Lesson Summary

This lesson established that ports are 16-bit identifiers (0–65,535) that enable application-level multiplexing on a networked host, and that protocols define the rules governing data exchange at each layer of the TCP/IP stack. We examined TCP (connection-oriented, reliable delivery via three-way handshake, vulnerable to SYN floods) and UDP (connectionless, fast, vulnerable to amplification attacks). Key application-layer protocols include DNS (port 53, resolves domain names, threatened by cache poisoning and tunneling), DHCP (ports 67/68, automates IP assignment, vulnerable to rogue servers), HTTP/HTTPS (ports 80/443, with HTTPS adding TLS encryption for confidentiality and integrity), and SSH (port 22, providing encrypted remote access to replace insecure Telnet).

The security implications are clear: every open port expands the attack surface, and unencrypted protocols expose sensitive data to interception. The principle of least privilege demands that only required ports remain open, while defense in depth layers encryption, authentication, intrusion detection, and monitoring across all exposed services. As protocols converge onto port 443, security must evolve beyond port-based filtering toward application-aware inspection, zero-trust architectures, and behavioral analytics to maintain effective network security.

Varsity Tutors • Cyber Security • Ports & Common Protocols