Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is it possible to setup a Linux system so that it provides more than 65,535 ports? The intent would be to have more than 65k daemons listening on a given system.

Clearly there are ports being used so this is not possible for those reasons, so think of this as a theoretical exercise in trying to understand where TCP would be restrictive in doing something like this.

share|improve this question
5  
What is the motivation for this question? Why do you want to have that many daemons listening? –  Warren Young May 18 at 9:07
1  
Also, you're going to have a hard time starting that many processes. (I assume you mean one process per daemon.) –  Warren Young May 18 at 9:16
6  
While there is nothing that formally restricts you from wearing 65 pairs of trousers at once, it would be practical idiocy to try. If you can show me a machine that can fruitfully process 10'000 TCP ports concurrently, then this might be an interesting abstract question. –  msw May 18 at 11:28
5  
The nature of this Q is completely theoretical, no intended purpose other than to understand the limitations of TCP & the # of ports. –  slm May 18 at 13:07
1  
@WarrenYoung - that's doubtful 8-). I have access to many systems with 256GB RAM or more if needed. Truth this Q is a proxy for the A that I wanted to write. This Q came up in the chatroom and while researching it I found little that explained why so I was creating that content on the interwebs. Even systems with 48GB or 64GB are readily available, we have several at my day job. –  slm May 18 at 14:25

2 Answers 2

up vote 46 down vote accepted

Looking at the RFC for TCP: RFC 793 - Transmission Control Protocol, the answer would seem to be no because of the fact that a TCP header is limited to 16-bits for the source/destination port field.

    ss #1

Does IPv6 improve things?

No. Even though IPv6 will give us a much larger IP address space, 32-bit vs. 128-bits, it makes no attempt to improve the TCP packet limitation of 16-bits for the port numbers. Interestingly the RFC for IPv6: Internet Protocol, Version 6 (IPv6) Specification, the IP field needed to be expanded.

When TCP runs over IPv6, the method used to compute the checksum is changed, as per RFC 2460:

Any transport or other upper-layer protocol that includes the addresses from the IP header in its checksum computation must be modified for use over IPv6, to include the 128-bit IPv6 addresses instead of 32-bit IPv4 addresses.

                 ss #2

So how can you get more ports?

One approach would be to stack additional IP addresses using more interfaces. If your system has multiple NICs this is easier, but even with just a single NIC, one can make use of virtual interfaces (aka. aliases) to allocate more IPs if needed.

NOTE: Using aliases have been supplanted by iproute2 which you can use to stack IP addresses on a single interface (i.e. eth0) instead.

Example

$ sudo ip link set eth0 up
$ sudo ip addr add 192.0.2.1/24 dev eth0
$ sudo ip addr add 192.0.2.2/24 dev eth0
$ ip addr show dev eth0
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc
      pfifo_fast state DOWN qlen 1000
    link/ether 00:d0:b7:2d:ce:cf brd ff:ff:ff:ff:ff:ff
    inet 192.0.2.1/24 brd 192.0.2.255 scope global eth1
    inet 192.0.2.2/24 scope global secondary eth1

Source: iproute2: Life after ifconfig

References

share|improve this answer
1  
It would not be possible to select among 65,536+ daemons using the destination port alone, but if one had unlimited memory and bandwidth, could have over 32,000 connections with every distinct TCP address on every incoming port. –  supercat May 19 at 3:18

Is it possible to setup a Linux system so that it provides more than 65,535 ports?

Nope.

The intent would be to have more than 65k daemons listening on a given system.

Then you need:

  • an iptables configuration that redirects on traffic content or

  • a "service broker service" or "multiplexor service" that will accept incoming connections on a single port and route it to the appropriate daemon "behind it". If you want standard protocols to pass unmodified you may have to implement protocol sniffing/recognization in this multiplexor service, in a fashion that an IDS or layer-7 firewall would anaylze; completely possible with the great majority of protocols.

Per the second item, you could design this service to handle more than 2^16 "ports" if you really wanted to. I'm sure the performance impact will be minimal compared to the load of 2^16+ listeners running.

Daemons in Linux can be listening on unix sockets which exist in the filesystem, so your "multiplexor service" could maintain an internal mapping of external port <-> internal unix socket. You'll likely run into a kernel process limit (32Kbyte processes?) before running out of inodes on any modern filesystem.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.