Sunday, 7 April 2019

How to increase the port range in Linux


Lots of time we required a lot of opening connections from Linux servers like for Load or performance testing or benchmarking of servers. To achieve this we might need to utilize the utmost capacity of the servers. To utilize utmost from the server we might need to modify some of the kernel parameters of the server.
The default range is less, we might need to increase the range. Using sysctlutility or command we can modify kernel parameters.

Check the current port range:

Below commands, we can use to check the current port range.
cat  /proc/sys/net/ipv4/ip_local_port_range
                   or 
 sysctl net.ipv4.ip_local_port_range
OUTPUT:
net.ipv4.ip_local_port_range = 2028   32768

Set the new port range:

As we know that default ports range that is reserved for the kernel is 0–1023, and total no of ports in the kernel is 2¹⁶ ==65536 so we can use maximum from 1024 to 65535. Let’s see how can we set.
echo 1024 65535 > /proc/sys/net/ipv4/ip_local_port_range
               ORsudo sysctl -w net.ipv4.ip_local_port_range="1024 65535"
Note: To set this range or modify kernel parameters you should have root privileges.
To make a permanent change in the server update or add net.ipv4.ip_local_port_range = 1024 65535 this to /etc/sysctl.conf.
We can use ss or netstat command to validate or check all active connections.
That’s it.
Thanks and Happy Learning.

No comments:

Post a Comment

Generating Unique Id in Distributed Environment in high Scale:

Recently I was working on a project which requires unique id in a distributed environment which we used as a  primary  key to store in dat...