Nov 2, 2011
tom

Does the TCP source port have to be unique per host?

Question

I’ve learned that a TCP connection is identified by the tuple (source IP, source port, destination ip, destination port). Theoretically, it should thus be possible to have a client from host1:port1 connect to server1:port1 and at the same time another client (running on host1) from host1:port1 to server2:port1.

I’ve tested a bit in Java, and so far it seems possible.

However, I’ve read multiple times that the source port has to be unique for the host address, which would basically mean that there is a hard limit of at most 65536 concurrent outgoing TCP connections. Is that true?

Answer

It’s not a TCP requirement. As far as TCP is concerned, only the combination of source IP, source port, destination IP, and destination port needs to be unique. However, in practice most TCP APIs don’t provide any way to create more than one connection with the same source port, unless they have different source IP addresses.

Related posts:

  1. Where is documented that TCP and UDP source port should be over 1024 and random?
  2. Where is the documentation that states TCP and UDP source port should be over 1024 and random?
  3. IIS7 Hosted Site Accessable Unique Port But Not Host Header
  4. Host information with TCP port
  5. Unix socket vs TCP/IP host:port

Leave a comment