I am trying to benchmark a web framework and read that not having enough free ephemeral ports can falsify the results. Unfortunately, I haven't found what the ephemeral port range is on my mac, or how to display it ?
Different OSs use different port ranges for ephemeral ports. Windows versions (until XP) use 1025 – 5000. Later Windows versions, including Vista, Windows 7 and Server 2008, use the Internet Assigned Number Authority (IANA) suggested range of 49152 – 65535.
The ephemeral ports on OpenBSD are actually two separate ranges, the regular range, and the alternate "high" range. Below is an example showing how to use sysctlto view the current configuration of these two ranges: # /usr/sbin/sysctl net.inet.ip.portfirst net.inet.ip.portlast net.inet.ip.porthifirst net.inet.ip.porthilast
However, it is usually reused only after the entire port range is used up. Different operating systems (OS) use different port ranges for ephemeral ports. Many Linux versions use port range 32768-61000, while Windows versions (until XP) use 1025-5000, by default.
When the connection terminates, the ephemeral port is available for reuse, although most IP stacks won't reuse that port number until the entire pool of ephemeral ports have been used. So, if the client program reconnects, it will be assigned a different ephemeral port number for its side of the new connection.
Here, a good article on the topic, addressing also the issue of TIME_WAIT for ephemeral ports. The port range on macOS can be displayed by:
>> sysctl net.inet.ip.portrange.first net.inet.ip.portrange.last
net.inet.ip.portrange.first: 49152
net.inet.ip.portrange.last: 65535
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With