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:
netstat -an | egrep -c 'tcp|udp'
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. :)
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.
Post a Comment