views:

247

answers:

5

Hi,

Why does the client end of a connection use high port number(ephemeral ports) whereas the applications listen on typically small port numbers ?

Thx in advans, Karthik Balaguru

A: 

Lower port numbers (< 1024) are reserved to privileged processes. In addition, many of these ports are assigned to specific services by the Internet Assigned Number Authority. Clients establish connections to servers listening on these well-known ports, but use dynamically assigned port numbers in the higher ranges according to the ports that are available to them.

tvanfosson
A: 

Lower port numbers are typically reserved for common applications. Shorter = easier to remember.

Spencer Ruport
+3  A: 

Ports numbers under 1024 are called "registered", while those above (limit of 65,535) are called "unregistered". All these two terms mean is that ports under 1024 have standard services associated with them. IE: 53 for DNS, 80 for HTTP, 25 for SMTP, etc. Note they are associated - there is nothing to stop you from setting your application to use port 53, 25, etc but it's not recommended because other services will attempt to connect and or operate on these ports so it could cause problems.

The unregistered port region is dynamically used by client applications. IE: You are reading this answer while connecting to port 80 of the StackOverflow.com webserver(s), but your browser is using an unregistered port to initiate that request.

OMG Ponies
Actually IANA calls ports 1024..49151 "registered" -- see the link in my answer for details. Also there is something stopping you from using port 53 or 25, if you are not root.
mark4o
You can't use ports below 1024 unless as root or proxy service on *nix systems only. This is not the case on Windows.
OMG Ponies
+1  A: 

Because server ports are usually well known ports. On a Unix box you will see their assignment in /etc/services file. The client ports, on the other hand, are usually picked by TCP/IP stack from the specific high range. So servers know what ports to listen on, clients know what port to connect to, and nobody cares what port the connection is made from.

Nikolai N Fetissov
+2  A: 

Servers listen on a fixed port number so that clients will know where to connect. Clients do not need to use a fixed port number, since no one is initiating a connection to them, and in fact they cannot use a fixed port number if there may be more than one client running on the same machine (e.g. a web browser) connecting to the same server. IANA has designated ports in the range 0..49151 as fixed port numbers for specific services, and ports in the range 49152..65535 as dynamic (ephemeral) ports which are not assigned to any service and can be used when a fixed port number is not required.

The port range 0..49151 is further divided into the well known range 0..1023, which only a privileged process can bind to (at least on Unix/Linux), and the registered range 1024..49151. Ports in the range 1024..49151 can be used by server processes that may run as an unprivlieged user, and it is also possible for clients to use ports in this range if they are not being used by a server (e.g. dynamic ports on Linux and Solaris start at 32768 by default, rather than 49152).

mark4o