Is there a hard limit of 65536 open TCP connections per IP address on linux? I read somewhere that there was, but someone is asking for confirmation and i just can't find it.

I seem to remember it was something about the file descriptors being a 16 bit integer which limits it somehow?

Or is this hokum, and is there simply no limit other than how beefy the server is?


You may be thinking of number of ports. There are 65536 ports available in the TCP in the current versions of IPv4. This is not just a Linux limitation, its part of the protocol. Your IP address identifies your machine, and the port identifies a program on your machine.

But, the number of connections isn't limited by that. A connection consists of 5 pieces of info, in geek speak a 5-tuple. It is determined by protocol (TCP, UDP), local IP address and port, and remote IP address and port. So, take a webserver. It can service many connections on the same port (most likely 80). Your webserver can even support multiple connections to the same client machine. Say, you're connecting to google.com from two windows. Your machine will pick an unused port for each connection. So, google's server will have to keep track of (TCP, google.com, 80, yourmachine, someport1) and (TCP, google.com, 80, yourmachine, someport2). At some point you'd bump into limits, but it's not a hard limit, and is very system dependent.

And yes, each socket is a file descriptor, but not all machines use shorts for the fd table. On my system, a not tuned at all system, cat /proc/sys/fs/file-max gives 323997. I'm sure I could boost it if I needed to.

So, there is a limit of 65336, but it has to do with addressing, not number of connections. Number of connections is limited, but more by system config, and how much memory it has.

  • 2
    So, re the 5-tuple: even though i'm limited to 65536 ports, that only limits me to 64k connections per incoming IP address, is that right? So the only limit is the file descriptors, but they're not necessarily 16 bit? So basically what you're saying is there are no limits? – Chris Mar 1 '11 at 0:52
  • 1
    yes. See also: en.wikipedia.org/wiki/Transmission_Control_Protocol section "Resource usage" – user12889 Mar 1 '11 at 2:28
  • 3
    @Chris: 64k connections per incoming IP address on a single local port, yes. – grawity Mar 1 '11 at 13:28
  • @Chris what grawity said. The 5-tuple will have up to (but never reaching) 65536 combinations with the other machine. In reality, you'll never get there because a machine can't use any old port for a connection - some are reserved for specific reasons. – Rich Homolka Mar 2 '11 at 18:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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