How to limit range of random port sockets

kernelnetworkingsocketsysctltcp

There's a binary that I need to run which uses bind with a port argument of zero, to get a random free port from the system. Is there a way I can constrain the range of ports the kernel is allowed to pick from?

Best Answer

on Linux, you'd do something like

sudo sysctl -w net.ipv4.ip_local_port_range="60000 61000" 

instruction for changing ephemeral port range on other unices can be found for example at http://www.ncftp.com/ncftpd/doc/misc/ephemeral_ports.html

Related Question