Sunday, February 7, 2010

Linux: EADDRNOTAVAIL (Address not available) error


If you are running many TCP client programs on your machine and these programs do not specify ports when they make connections to the server, the system would assign temporary ports for them. When a connection is closed, the port will be returned to the system for reuse. The temporary ports have a limited range. When the allowed connections are exhausted, the program could get an error when it tries to make any new connections. The error number it generates would be EADDRNOTAVAIL (Address not available).

In such case, you can check the range of the temporary ports with:
      cat /proc/sys/net/ipv4/ip_local_port_range

The command returns two numbers, such as
      1024 4999

The first number is the minimum and the second one is the maximum value of the temporary port. In this example, we have 3976 ports that can be used.

You can check how many TCP and UDP are used on your machine by running command:
      netstat -an | grep -e tcp -e udp | wc -l

Although the result includes the ports used by the TCP/UDP servers running on your machines and other ports specified outside the ip_local_port_range, it gives you a sense of how heavy the network ports are used. Usually, those ports used by TCP/UDP servers should not be too many. If you are having dozens of thousands of ports opened on your machine, that could be the reason why you are getting error EADDRNOTAVAIL (Address not available).

You may then consider increase the value of ip_local_port_range. To do that, run this command as root:
      echo "32768 61000" >/proc/sys/net/ipv4/ip_local_port_range

To make the change permanent on each boot, you can make some changes on the configuration file /etc/sysctl.conf. Just add this line to the end of the file:
      net.ipv4.ip_local_port_range = 32768 61000

To verify the result, after rebooting, run:
      cat /proc/sys/net/ipv4/ip_local_port_range

3 comments:

Anonymous said...

netstat -an | egrep -c 'tcp|udp'

Charlie D said...

The port numbers you've used in your example are excellent, because now I know if someone else has read your article when I'm checking out a box for this problem. :)

jesus said...

You can also use "ss -s" to get a count of active connections. You can even combine that with the "watch" command to make it auto-refresh.

 
Get This <