Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the range of ephemeral ports on mac?

Tags:

macos

tcp

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 ?

like image 649
DarthVader1991 Avatar asked Sep 03 '17 12:09

DarthVader1991


People also ask

What is the range of ephemeral ports?

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.

What are the ephemeral ports on OpenBSD?

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

Can an ephemeral port be reused?

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.

What happens to the ephemeral port number when the connection terminates?

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.


1 Answers

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
like image 127
Felix Avatar answered Nov 04 '22 09:11

Felix