Does the TCP source port have to be unique per host?
Solution 1:
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.
Solution 2:
That's the maximum in practice it's usually lower. For example Linux uses the net.ipv4.ip_local_port
kernel parameter to define the ports that are used for outbound connections. This is usually something like
sysctl net.ipv4.ip_local_port_range 32768 to 61000
You can increase the number available with sysctl e.g.
sysctl -w net.ipv4.ip_local_port_range="10000 64000"
or you can edit /etc/sysctl.conf with the same information
net.ipv4.ip_local_port_range = 10000 65535
All of the examples I've found show the minimum value to be 1024 too.
Solution 3:
In addition to Iain's answer (above), that there might only be 10,000 ports allowed for outgoing connections by your kernel, in theory your at least limited to one set of XX,XXX ports per IP address on the adapter. Since 127.1 isn't available to the outside world, being on the local network, then for each other IP address (external ) you have a set of outgoing ports within your 65K port range.
So the outgoing limit is really :
With 1 IP Address: XX,XXX (or 2 x XX,XXX on internal network)
With 2 IP addresses: 2 x XX,XXX (or 3 x XX,XXX on internal network)
With 3 IP addresses: 3 x XX,XXX (or 4 x XX,XXX on internal network)
etc.
To make this work, you would need to read the answer to this thread.
Solution 4:
Yes. This is true.
Ports are to bind and the apps with the network.
You cannot have more than 65553 application connected by TCP and 65535 connect by UDP on the same host. Operating Systems tipically dinamycally managed the ports an assign one for each app that connects to the network.
If you have two applications listeing on the same port when a network package arrives the computer couldn't know to what app is going to deliver the data. As example if you have Messenger and Skype on the same binded to the same port your messenger message will appear in skype and vice versa :)