Maximum number of sockets per server

linux-networkingsocket

Pardon me if this question doesn't make sense! Is there any theoretical limit for the number of sockets that can be used simultaneously ? As per my understanding sockets are bound to ports and ports can have a value up to 65535, is this the theoretical limiting factor for the socket count?

Best Answer

You can check the link provided by @Chopper3 for a more detailed explanation, but the short answer will be no.

DETAILS

In a single IP you can have up to 65535 TCP ports + 65535 UDP ports. This is limited by the Source and Destination fields in the TCP and UDP header, which are 16 bit length. This applies both for IPv4 and IPv6.

CONSIDERATIONS

Take into account that this is a theoretical number. There are well-known ports and in a real running system there may be services that are already using some ports so there will be less ports available.

Remember that a socket is always bounded to a IP and port number. So if you need more ports you can always allocate more IPs for your host. Each IP would double your amount of available ports. You can easily achieve this:

  • If you have/need to use multiple NICs, by configuring additional IPs in each device.
  • If you are using one single NIC you can create as many virtual interfaces as you need and assing IP addresses to them.
  • Assing mutliple IPs to the same interface (issued by the ip command).