Operating System - HP-UX
1832764 Members
3146 Online
110045 Solutions
New Discussion

Re: Limit in the number of socket port in machines with Unix

 
SOLVED
Go to solution
Ana Lizcano
Occasional Contributor

Limit in the number of socket port in machines with Unix

Hi,
my question is , there are any limit in the number of socket port in machines with Unix??
If there is a limit , which is the maximum number??
Thanks in advance.

Ana.
2 REPLIES 2
Paul R. Dittrich
Esteemed Contributor
Solution

Re: Limit in the number of socket port in machines with Unix

Ana, assuming I understand your question correctly, the answer is 65535 (64k) but that is not a Unix-related limitation.
The low number ports (0-1023) are called the "well-known" ports for services such as FTP, SMTP, HTTP, etc. and only the root user or a privileged process can use them as source ports.
Port numbers 1024-49151 are called "registered" ports. They can be used by ordinary users and are only registered for convenience.
Port numbers 49152-65535 are called "dynamic" or sometimes, "private" ports and I don't believe anyone keeps a listing of their usage.

You may find this URL useful:
http://www.iana.org/assignments/port-numbers

HTH,
Paul

Armin Feller
Honored Contributor

Re: Limit in the number of socket port in machines with Unix

Sockets are actually allocated out of dynamic memory and thus, the number is not
limited by a table directly. The
real limiting factors are typically file table entries or port numbers. When an
application creates a socket with the
socket(2) system call or accepts a new network connection with the accept(2)
system call, the operating system must
allocate a file descriptor to point to the newly allocated socket structure.

This means that there needs to be space in the kernel file table, the size of
which is controlled by the kernel tunable
"nfile". Typically if the kernel file table is full or near full, there will be
other problems with the system such as problems
starting new programs and there will be messages on the console indicating "file
table overflow".

Each process on the system also has has a table of file descriptors which is
typically limited to 60 open files per
process. This is more often an issue than is the kernel file table. The number
of open "files", including sockets is
controlled by the kernel tunable called "maxfiles".

Finally, a TCP or UDP port number must be assigned to each socket before it
actually gets used for communications.
The port number is assigned explicitly with the bind(2) system call or
implicitly with a connect(2) call, a sento(2) call
or a bind(2) call with a port number of 0. If the application asks for a
specific port number using the bind(2) call, it will
get an error if that port number is not available. If the application lets the
system allocate a port number, the port will
come out of a pool of numbers. The port numbers used for such allocation are
from 1024 to 5000 on a standard 10.20
system. If and "ARPA transport" patch starting with [PHNE_13287/PACHRDME/English] or later is
installed then you also have the option
of specifying a different range of port numbers using the nettune command.

/usr/contrib/bin/nettune -l high_port_enable

will display if the use of "high" port numbers is enabled (use "nettune -s
high_port_enable 1" to enable high port numbers)

When the use of high port nmbers is enabled the dynamically (aka ephemeral) port
numbers will be allocated starting at
port number 49152. The upper port number is, by default, 65535. The lower limit
is fixed but the upper limit can be
reduced, if desired using:

/usr/local/bin/nettune -s high_port_max 60000

This will set the range to be from 49152 to 6000, thus allowing for 10,848
dynamically allocated port numbers.

The nettune command modifies the running kernel only and thus must be run during
system startup.
The use of "high ports" should be avoided unless you are sure you are actually
being limited by a lack of port
numbers. This would typically only be a problem on system running a very large
number of outbound conections.

The use of "high ports" has no impact on use of "reserved ports" which are in
the range from512-1204. The reserved port