Linux Increase Local Port Range with net.ipv4.ip_local_port_range Kernel Parameter

Posted on in Categories High performance computing, Linux, Linux Scalability, Networking, Troubleshooting, Tuning last updated November 2, 2007

Linux Local Port Range
If your Linux server is opening lots of outgoing network connections, you need to increase local port range. By default range is small. For example a squid proxy server can come under fire if it runs out of ports.

You can use the sysctl command to to modify kernel parameters at runtime. The parameters available are those listed under /proc/sys/. Please note that this hack is only useful for high bandwidth, busy Linux servers or large scale grid servers.

How to find current port range type

Type the following command
$ sysctl net.ipv4.ip_local_port_range
Sample outputs:

net.ipv4.ip_local_port_range = 32768    61000

Set new local port range

You can set the range with any one of the following command. You must be root user:
# echo 1024 65535 > /proc/sys/net/ipv4/ip_local_port_range
OR
$ sudo sysctl -w net.ipv4.ip_local_port_range="1024 64000"

Finally, edit /etc/sysctl.conf file, to make changes to /proc filesystem permanently i.e. append the following line to your /etc/sysctl.conf file:
# increase system IP port limits
net.ipv4.ip_local_port_range = 1024 65535

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

14 comment

  1. worth mentioning…

    when adding ip_local_port_range to your sysctl.conf file, i had to use a tab between the 2 values or else the 2nd value was not being read correctly.

    centos5.2 w/ 2.6.18 vanilla.

    ciao.

  2. I have changed the value to 31000 65535 but after few days it again came back to 1024 65535. May I know what is the reason for this ?

    I used the following to change
    echo 31000 65535 > /proc/sys/net/ipv4/ip_local_port_range

    Thanks in advance

Leave a Comment