Network Ports and Ranges

The Media Server listens on configurable ranges of network ports for its MRCP and RTP traffic. If those ranges collide with the ports the host operating system allocates dynamically — its ephemeral ports — connections will fail intermittently, and in ways that are difficult to diagnose. Avoiding that collision is the practical reason to understand how ports are assigned. This article explains what ephemeral ports are, how to find your host’s ephemeral range, and how to keep the Media Server’s port ranges clear of it.

Network ports

Any application that communicates over a network uses a “port” as a reference to a specific connection endpoint — typically one port on the client and another on the server it is communicating with. A machine has a finite number of ports available.

Certain port numbers have special meaning. Port 80, for example, is the standard HTTP port used when you browse to a website. Many other “well-known” ports — generally in the range 1 to 1024 — are reserved for established purposes such as FTP, network management, and timekeeping, and should not be used by general-purpose applications, to avoid conflicts.

It helps to think of a port number as a telephone extension and the server as the exchange: connecting to a website on port 80 is like dialing the extension that reaches its web service. Every connection into or out of a server needs a port — either a specifically assigned number, or one assigned dynamically by the operating system as an ephemeral port.

A further wrinkle is that connections can be either TCP or UDP. These are independent, so a UDP connection and a TCP connection from two different applications can share the same numeric port without interfering — though it is best to avoid configurations that rely on this. This article is not an exhaustive treatment of network programming, but an overview of why port numbers warrant consideration.

What are ephemeral ports?

Ephemeral ports are managed internally by the operating system, whether that is Linux, Windows, or any other networked OS. They are used when an application needs to make a connection but does not need to bind it to a specific port number. The application effectively asks the operating system to choose an available port, which relieves the application of tracking which ports are in use. The number is assigned dynamically at the time of the request, and when the application is finished with the port, it is returned to the operating system’s pool for reuse — by the same application later, or by another.

When are ephemeral ports used?

Consider a browser connecting to a website. The browser connects to the site’s IP address on port 80 (the HTTP port) — that is the port at the server end of the connection. The port at the client end generally does not matter, so the browser asks the operating system for one of its ephemeral ports, selected from the pool the OS manages.

This happens automatically, and the port numbers at the client and server ends of a connection are rarely the same.

Why port ranges need consideration

If applications never needed specific ports, ephemeral allocation would be invisible. The complication arises when an application must use a particular port. A web server needs port 80 so browsers can reach it; if port 80 fell inside the server’s ephemeral range, there would be no guarantee it was free when the web service started. The same applies to any application — including the Media Server — that binds fixed ports.

For this reason, the fixed port ranges an application uses must be kept clear of the operating system’s ephemeral range. When several applications on a host each bind their own ports, overlapping ranges mean two applications may contend for the same port, and only one will succeed — whichever reaches it first.

Default ephemeral port ranges

The default ephemeral ranges chosen by operating systems have varied over time and across systems, with little consistency. The diagram below illustrates the defaults for several common operating systems. Bear in mind that any of these can be reconfigured on an individual host.

Default ephemeral port ranges: IANA 49152-65535, Linux 32768-61000, Windows XP and prior 1025-5000, Windows 7/Vista/2008 49152-65535

Checking your ephemeral port range

Depending on your operating system, you can determine the ephemeral (dynamic) port range currently in effect.

Linux

Run the following from a terminal:

# cat /proc/sys/net/ipv4/ip_local_port_range
32768   61000

The second line is the range — here, 32768 to 61000, typical of modern Linux systems.

Windows

Run the following from a command prompt:

> netsh int ipv4 show dynamicport tcp

Protocol tcp Dynamic Port Range
---------------------------------
Start Port     : 49152
Number of Ports : 16384

This reports the TCP ephemeral range as 49152 to 65535, typical of modern Windows systems. Substitute udp for tcp to view the UDP range, which is normally identical. Both ranges can be modified, though the procedure is beyond the scope of this article.

Media Server MRCP and RTP port ranges

The Media Server uses two configurable ranges of ports for the connections clients make over MRCP and RTP, whether the control protocol is SIP or RTSP. Because these are fixed ranges rather than ephemeral ones, they must not overlap the host operating system’s ephemeral range. If they do, the OS may hand an ephemeral port to another process that the Media Server expects to bind, producing intermittent connection failures.

By default, the MRCP control range starts at port 20000 and the RTP media range starts at port 25000. On Linux, whose ephemeral range typically begins at 32768, these defaults sit safely below the ephemeral floor. Even so, ephemeral ranges can be reconfigured per host, so confirm your host’s range (as shown above) and adjust the Media Server’s port-base settings if you find any overlap.

Authoritative reference
For how the Media Server allocates ports as calls arrive, how the width of each range relates to MEDIA_SERVER__NUM_CHANNELS, and the exact MEDIA_SERVER__MRCP_PORT_BASE and MEDIA_SERVER__RTP_PORT_BASE settings, see MRCP Ports and Channels. To configure these values, see Configuring Media Server Parameters.

Conflicts with other applications

This consideration is not unique to the Media Server — any application that binds network ports on a host is subject to the same conflicts. If you run other applications on the same host, check which port ranges they use and adjust configurations to avoid overlap.

The problem is also not limited to ephemeral ports. If two applications on the same host are configured to use the same fixed port, only one will bind successfully; in some cases, an application may even receive data intended for another. Like dialing the wrong telephone number, such conflicts are confusing at best and can be difficult to diagnose, so it is worth mapping port usage deliberately across the host.

Firewalls

Knowing which ports and ranges a host uses also allows your network team to configure firewalls correctly and to apply data-center or network-topology policies. For any connection that crosses a host boundary, it is important to know what each connection does, so that the right ports can be permitted inbound and outbound.

The Media Server is designed so that its ports and port ranges can be adjusted and configured as needed. These are set through the Media Server configuration; see Configuring Media Server Parameters and Media Server Specific Parameters for details.

Additional references

Related articles


Was this article helpful?