Calculating available ephemeral ports

%3CLINGO-SUB%20id%3D%22lingo-sub-1710279%22%20slang%3D%22en-US%22%3ECalculating%20available%20ephemeral%20ports%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1710279%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20seem%20to%20be%20running%20short%20of%20ephemeral%20ports%20for%20tcp%20connections%20on%20IPv4.%20This%20has%20lead%20me%20to%20try%20get%20a%20solid%20understand%20of%20just%20how%20many%20ephemeral%20(eph)%20ports%20I%20have%20available%20for%20IPv4%20tcp%20connections.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20start%20with%20the%20output%20from%26nbsp%3B%3CEM%3Enetsh%20int%20ipv4%20show%20dynamicport%20tcp%26nbsp%3B%3C%2FEM%3Ewhich%20outputs%20I%20have%2016384%20ports%20in%20my%20tcp%20Dynamic%20Port%20Range.%20I%20know%20I%20can%20increase%20this%20number%20but%20this%20is%20just%20a%20calculation%20exercise.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENow%20assume%20my%20server%20has%20multiple%20NICs%20and%20of%20course%20multiple%20IPs%20as%20well%20as%20loopback%20-%20127.0.01.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20kind%20of%20doubt%20that%20I%20have%20only%2016384%20eph%20ports%20available%20across%20the%20entire%20host%20regardless%20of%20the%20number%20of%20local%20IPs.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPerhaps%20I%20have%2016384%20eph%20ports%20available%20per%20local%20IP.%20That%20makes%20more%20sense.%20But%20I%20know%20in%20terms%20of%20making%20a%20unique%20tcp%20connection%20I%20need%20a%20eph%20port%20for%20each%20outgoing%20connection%20to%20a%20foreign%20host's%20individual%20listener.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMy%20port%20exhaustion%20seems%20to%20be%20on%20loopback%20so%20let%20me%20put%20my%20question%20like%20this%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eusing%20this%20format%20%3A%20LocalHost%3AephPort%20--%26gt%3B%26nbsp%3B%20RemoteHost%3AListener%3C%2FP%3E%3CP%3Efor%20example%2C%20do%20I%20have%3C%2FP%3E%3CP%3Ea)%20%3CEM%3E127.0.0.1%3AEphPort%5B16384%20possibilities%5D%20--%26gt%3B%20127.0.0.1%3A443%20and%3C%2FEM%3E%3C%2FP%3E%3CP%3E%3CEM%3E127.0.0.1%3AEphPort%5B16384%20possibilities%5D%20--%26gt%3B%20127.0.0.1%3A444%20and%20so%20on%3C%2FEM%3E%3C%2FP%3E%3CP%3Eor%26nbsp%3B%3C%2FP%3E%3CP%3Eb)%26nbsp%3B%3CEM%3E127.0.0.1%3AEphPort%5B16384%20possibilities%5D%20--%26gt%3B127.0.0.1%3A%5Bregardless%20of%20listener%5D%3C%2FEM%3E%3C%2FP%3E%3CP%3Eor%3C%2FP%3E%3CP%3Ec)%20%3CEM%3EHost%3A%26nbsp%3BEphPort%5B16384%20possibilities%5D%20--%26gt%3B%20RemoteHost%3C%2FEM%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnother%20thing%20that%20has%20lead%20to%20my%20question%20above%20is%20the%20word%26nbsp%3B%3CEM%3Eglobal%3C%2FEM%3E%20in%20event%20%234231%20I%20am%20getting.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%22A%20request%20to%20allocate%20an%20ephemeral%20port%20number%20from%20the%20%3CSTRONG%3Eglobal%3C%2FSTRONG%3E%20TCP%20port%20space%20has%20failed%20due%20to%20all%20such%20ports%20being%20in%20use.%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPerhaps%20I%20should%20have%20just%20asked%20for%20the%20definition%20of%20the%26nbsp%3B%3CEM%3Eglobal%20TCP%20port%20space.%3C%2FEM%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E-Wes%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1710279%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ENetworking%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EWindows%20Server%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1710666%22%20slang%3D%22en-US%22%3ERe%3A%20Calculating%20available%20ephemeral%20ports%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1710666%22%20slang%3D%22en-US%22%3E%3CP%3EThere%20are%26nbsp%3B%3CSPAN%3E65%2C535%20possible%20ports%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1710945%22%20slang%3D%22en-US%22%3ERe%3A%20Calculating%20available%20ephemeral%20ports%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1710945%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F51719%22%20target%3D%22_blank%22%3E%40Dave%20Patrick%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPerhaps%20you%20mean%20%3CSPAN%3E65%2C535%3C%2FSPAN%3E%20per%20server%20for%20TCP%20connections%20across%20all%20NICs%2FIPs%20and%20including%20connections%20on%20127.0.0.1.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnd%20once%20you%20hit%20that%20you%20need%20to%20start%20adding%20more%20servers%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
New Contributor

Hi,

 

I seem to be running short of ephemeral ports for tcp connections on IPv4. This has lead me to try get a solid understand of just how many ephemeral (eph) ports I have available for IPv4 tcp connections.

 

I start with the output from netsh int ipv4 show dynamicport tcp which outputs I have 16384 ports in my tcp Dynamic Port Range. I know I can increase this number but this is just a calculation exercise.

 

Now assume my server has multiple NICs and of course multiple IPs as well as loopback - 127.0.01.

 

I kind of doubt that I have only 16384 eph ports available across the entire host regardless of the number of local IPs.

 

Perhaps I have 16384 eph ports available per local IP. That makes more sense. But I know in terms of making a unique tcp connection I need a eph port for each outgoing connection to a foreign host's individual listener.  

 

My port exhaustion seems to be on loopback so let me put my question like this:

 

using this format : LocalHost:ephPort -->  RemoteHost:Listener

for example, do I have

a) 127.0.0.1:EphPort[16384 possibilities] --> 127.0.0.1:443 and

127.0.0.1:EphPort[16384 possibilities] --> 127.0.0.1:444 and so on

or 

b) 127.0.0.1:EphPort[16384 possibilities] -->127.0.0.1:[regardless of listener]

or

c) Host: EphPort[16384 possibilities] --> RemoteHost

 

Another thing that has lead to my question above is the word global in event #4231 I am getting.

 

"A request to allocate an ephemeral port number from the global TCP port space has failed due to all such ports being in use."

 

Perhaps I should have just asked for the definition of the global TCP port space.

 

Thanks,

 

-Wes

 

5 Replies
Highlighted

There are 65,535 possible tcp and udp ports

 

 

Highlighted

@Dave Patrick 

 

Perhaps you mean 65,535 per server for TCP connections across all NICs/IPs and including connections on 127.0.0.1. 

 

And once you hit that you need to start adding more servers?

 

 

Highlighted

You asked about limits of port space so I was answering that. (65,535)

 

Generally if a process uses some dynamically assigned range of ports and didn't complete (and close) successfully and is repeatedly being triggered then it may be expected behavior to eventually run out of ports.

 

netstat -aon

 

should show the result. The short term fix is to reboot. A long term solution is fixing the problem process or connection issues.

 

 

Highlighted

@Dave Patrick 

 

These are big servers with thousands of users. Netstat outputs about 180K lines, most of the time netstat doesn't complete, same for the PS Get-NetTCPConnection. This doesn't appear to be a process leaving connections open; I think its just a busy box running up against an ephemeral limit which is why I would like to know what the global TCP port space actually is.  From that perhaps we could figure if there is anyway to add more ephemeral ports, that is, allow more connections.

 

Highlighted

May depend on the process or service. Some windows services port usage are listed here.

https://docs.microsoft.com/en-us/troubleshoot/windows-server/networking/service-overview-and-network...

 

The space is up to 65,535 but of course you'll need to know what's being used by windows and or other processes so as not to cause conflicts.