Linux Increase Local Port Range with net.ipv4.ip_local_port_range

by on November 2, 2007 · 10 comments· LAST UPDATED November 2, 2007

in , ,

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

You can use 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.

To find current range type

$ sysctl net.ipv4.ip_local_port_range
Output:

net.ipv4.ip_local_port_range = 32768    61000

Set new local port range

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

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

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 10 comments… read them below or add one }

1 evilaim February 24, 2009 at 8:07 pm

Great walk through. This should help a lot of people.

Reply

2 tom3k August 5, 2009 at 10:12 am

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.

Reply

3 JSmith December 9, 2009 at 9:36 pm

Hi,

But it is possible to set port range per application basis?

regards.

Reply

4 pshankland January 16, 2013 at 10:01 pm

When I run ‘echo 1024 65535 > /proc/sys/net/ipv4/ip_local_port_range’ I keep getting:

-bash: /proc/sys/net/ipv4/ip_local_port_range: Permission denied

Any ideas?

Reply

5 nixCraft January 18, 2013 at 10:52 am

Run as root user.

Reply

6 kellogs April 11, 2013 at 11:40 pm

awful advice

Reply

7 CanadaDry August 1, 2013 at 6:39 pm

@kellogs
idiot, pull up your big boy pants and use root when necessary.

root gestapo stoppers unite

Reply

8 Drew November 22, 2013 at 1:18 pm

Uh how else would you write to this file?

Reply

9 Naidu June 7, 2013 at 8:21 am

What is the equivalent for QNX?

Reply

10 Samuel Antwi June 21, 2014 at 3:53 pm

pshanklandlogin as root and run it

Reply

Leave a Comment

Tagged as: , , , , , ,

Previous post:

Next post: