0

How to know the range for the allocation of dynamic ports on red hat Linux machine

From Linux we did

sysctl -a | egrep "net.inet.ip.portrange.first|net.inet.ip.portrange.last"

but those parameters are not in kernel configuration

is that parameters are equivalent to the setting in file - /proc/sys/net/ipv4/ip_local_port_range ?

more /proc/sys/net/ipv4/ip_local_port_range
1024    65535
King David
  • 781
  • 2
  • 14
  • 27

2 Answers2

0

The parameter you search for is net.ipv4.ip_local_port_range and the syntax in sysctl is:

net.ipv4.ip_local_port_range = 1024    65535

So your grep should be:

sysctl -a | egrep "net.ipv4.ip_local_port_range"

P.S. I did not found net.inet.ip.portrange.first, net.inet.ip.portrange.last to be valid kernel parameters

Romeo Ninov
  • 5,319
  • 5
  • 20
  • 20
0

I think the parameters you checked are for FreeBSD, not Red Hat. On Red Hat, you should check the range with:

sysctl net.ipv4.ip_local_port_range

The command will return min and max port numbers. And yes, you can also view the range by checking this file: /proc/sys/net/ipv4/ip_local_port_range

To change the range of dynamic ports on Red Hat, you can use

sysctl -w net.ipv4.ip_local_port_range="MIN MAX"

Replace the MIN and MAX with the desired new port ranges. Be sure you know what you are doing when changing these. For a permanent change, you need to edit the /etc/sysctl.conf file and add this line

net.ipv4.ip_local_port_range = MIN MAX

Save the file and run sysctl -p

lexivanx
  • 1
  • 2