| Lesson 6
| Ephemeral and reserved port numbers
| Describe the significance of ephemeral and reserved port numbers.
Ephemeral and Reserved Port Numbers
What are the ephemeral port numbers on Linux and Unix Operating systems?
Ephemeral port numbers, also known as dynamic or private ports, are temporary ports assigned by the operating system for client-side connections during network communication. They are used to distinguish between different client connections to a server and are released once the connection is closed.
On Linux and Unix operating systems, the default range for ephemeral port numbers typically starts at 32,768 (2^15) and goes up to 61,000, although some systems might have a different range. To check the current ephemeral port range on a Linux system, you can use the following command:
One possible output on a system could be:
This command will display the start and end values of the ephemeral port range. For example, if the output is "32768 61000", it means the range starts at port 32,768 and goes up to port 61,000.
Modify the ephemeral port Range
You can also modify the ephemeral port range on Linux by modifying the /proc/sys/net/ipv4/ip_local_port_range file or by using the sysctl command:
sudo sysctl -w net.ipv4.ip_local_port_range="new_start_port new_end_port"
On Unix-based systems like macOS, you can use the following command to check the ephemeral port range:
sysctl net.inet.ip.portrange.first net.inet.ip.portrange.last
The output will show the start and end values of the ephemeral port range, similar to the Linux command output. It is essential to keep in mind that the specific range for ephemeral ports may vary between different operating systems and distributions, and some applications or network configurations might require adjusting the range to better suit their needs.
A network server process must use a “well-known” port number so that potential clients can locate it. The client also needs a port number to create a TCP/IP connection, but this port number need not be well known. Clients are assigned port numbers by the operating system, as part of the sequence of system calls that create a network connection. These port numbers are called “ephemeral” because they are valid only for the life of the connection and have no special significance.
Reserved port numbers
Port numbers in the range 1 to 1023 are considered “reserved” or “privileged.” TCP/IP conventions require that a connection using such low port numbers have special privileges, such as root privileges on the originating machine.
On UNIX machines, a process cannot open a connection on low port numbers without root permissions.
An ephemeral port is a short-lived transport protocol port for Internet Protocol (IP) communications allocated automatically from a predefined range by the IP stack software. An ephemeral port is typically used by
- the Transmission Control Protocol (TCP),
- User Datagram Protocol (UDP), or
- Stream Control Transmission Protocol (SCTP)
as the port assignment for the client end of a client - server communication to a well-known port on a server. On servers, ephemeral ports may also be used as the port assignment on the server end of a communication.
This is done to continue communications with a client that initially connected to one of the well-known service listening ports of the server.
File Transfer Protocol (FTP) and Remote Procedure Call (RPC) applications are two protocols that can behave in this manner.
Note that the term "server" here includes workstations running network services that receive connections initiated from other clients (e.g. Remote Desktop Protocol).
The allocations are temporary and only valid for the duration of the communication session. After completion (or timeout) of the communication session, the ports become available for reuse.
Since the ports are used on a per request basis they are also called dynamic ports.
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