Network Daemons  «Prev  Next»

Lesson 6 Ephemeral and reserved port numbers
Objective Describe the significance of ephemeral and reserved port numbers in Linux

Ephemeral and Reserved Port Numbers

In TCP/IP networking, a port number identifies a process endpoint on a host. Servers typically listen on a known destination port, but clients also need a port for the source side of the conversation. Client-side ports are commonly assigned automatically by the operating system and are usually drawn from the ephemeral port range.

Ephemeral ports (also called dynamic or private ports) are temporary ports used to create short-lived endpoints for outbound connections. They exist for the life of a connection (TCP) or for the life of an application’s socket usage (UDP/SCTP), and they are later returned to the pool for reuse.

On modern Linux systems, the ephemeral range is configurable. A common default range is 32768–60999 (varies by distribution and kernel defaults). You can check your system’s active range with:


cat /proc/sys/net/ipv4/ip_local_port_range
  

Example output:


32768   60999
  

Changing the Ephemeral Port Range

You can adjust the range temporarily using sysctl. This can be useful in high-connection environments (proxies, load balancers, busy application servers) where port exhaustion becomes a risk.


sudo sysctl -w net.ipv4.ip_local_port_range="40000 65000"
  

To make changes persistent, place the setting in a sysctl configuration file (for example, /etc/sysctl.conf or a drop-in under /etc/sysctl.d/) and reload sysctl settings.

Reserved (Privileged) Port Numbers

Reserved (or privileged) ports are the low-numbered ports historically associated with core system services. On UNIX-like systems, binding to ports 0–1023 traditionally required elevated privileges (root or a process with the appropriate capabilities).

This convention exists so that a non-privileged user cannot easily impersonate a system service (for example, by binding to port 22 to mimic SSH). In modern Linux, “privileged port” behavior is still relevant, but it is often managed through Linux capabilities rather than requiring full root. For example, a service may be granted CAP_NET_BIND_SERVICE so it can bind to low ports without running as root.

The practical point for administrators is simple: well-known services tend to live on privileged ports, while client connections tend to originate from ephemeral ports.

Why Ephemeral Ports Matter in Real Networks

Ephemeral ports are not just a theory detail — they affect troubleshooting, performance, and security:

  • Connection identity: A TCP connection is uniquely identified by the “four-tuple” (source IP, source port, destination IP, destination port). Ephemeral ports make it possible for one client to maintain many simultaneous connections to the same server port.
  • NAT and firewalls: Most home and enterprise networks use NAT. NAT devices track outbound flows using ephemeral source ports and may rewrite them. Understanding ephemeral ports helps explain why “the same client” can appear to come from different source ports over time.
  • Port exhaustion: Systems that open many outbound connections can run out of ephemeral ports, especially when connections accumulate in TCP states like TIME_WAIT. The symptom looks like intermittent connection failures despite healthy DNS and routing.
  • Attack surface and scanning: Scanners often focus on well-known ports for exposed services, while defenders focus on minimizing listening ports and monitoring unexpected listeners. Ephemeral ports are typically outbound-only, but misconfiguration can accidentally expose services on high ports.

Ephemeral Ports Across TCP, UDP, and SCTP

The operating system’s ephemeral port pool is used across multiple transport protocols, but the behavior differs slightly by protocol:

  1. TCP: A client chooses an ephemeral source port when it establishes a connection to a server’s listening port. The port is tied to the connection and remains consistent until the connection closes.
  2. UDP: UDP is connectionless, but sockets still have local ports. A client may use an ephemeral port for a series of datagrams, and applications may reuse the same UDP port to receive responses.
  3. SCTP: SCTP also uses ports and may allocate ephemeral ports for client associations. SCTP supports multi-homing (multiple IPs per endpoint), but the port still helps identify the transport endpoint.

Across all three, the principle is the same: ephemeral ports provide temporary client endpoints while servers use stable listening ports that clients can predict.

TCP UDP Port Numbers - Quiz

Click the Quiz link below to take a short multiple-choice quiz on client/server processes, TCP, UDP, and port numbers.

TCP UDP Port Numbers - Quiz
SEMrush Software 6 SEMrush Banner 6