Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a method in Linux to check how many ephemeral ports are left available? I occasionally see "Address already in use" errors as a result of running out of ephemeral ports. A machine reboot will resolve this but it would be better to catch it before it happens.

share|improve this question
If you are hitting errors like that I would suggest that either you are either abusing the system by not using the right software or architecture for a job, or your software is misbehaving or misconfigured. Perhaps your timeouts are too long for your application or something is leaving connections open without using them? – Caleb Apr 20 '11 at 10:20
There are many valid applications that require additional ephemeral ports beyond OS defaults. – GregB Sep 16 '13 at 22:12

The ephermal port range is specified in /proc/sys/net/ipv4/ip_local_port_range. You can probably extend it to run from 16k to 64k.

You can see the number of open connections using netstat -an. Sockets may be stuck in TIME_WAIT state if you are opening and closing a lot of connections. In some places this is unavoidable, but you may need to consider if you need a pool of connection if this is the case.

If TIME_WAIT is the problem, you can set net.ipv4.tcp_tw_reuse / net.ipv4.tcp_tw_recycle to speed up connection turnover.

share|improve this answer
+1, thanks for taking the time to give this guy exact details. – Caleb Apr 20 '11 at 10:45
We have a range of 32800 to 61000. We just find that once these have been used the OS will not use them again. This is expected behaviour, but I would expect the OS to start again at the beginning once it reaches the last available port. This doesn't seem to happen though. Also, just to note, this isn't a hugely regular occurance. It is intermittent but we do have a large number of servers. – JMc Apr 20 '11 at 10:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.