2

I have tried to launch a script to listen to thousands of tcp ports (1000 to 10000) but it appears to be hitting a limit of 1024 listening ports. I've confirmed this via netstat and closed ports above certain ranges.

Is there a fixed limit of listening ports in linux and how, if possible, can this be raised?

2
  • what does sysctl net.ipv4.ip_local_port_range tell you? – Mike Feb 7 '15 at 14:17
  • Output below net.ipv4.ip_local_port_range = 32768 61000 – loloy.batoytoy Feb 8 '15 at 0:28
4

You are probably hitting at nofile limit, which is by default 1024.

Try raising ulimit -n in your shell before running the program, like:

$ ulimit -n 20480; ./myprogram

Offcourse, you have to have priviledge to raise nofile limit so high, so check current soft and hard limits with:

$ ulimit -a

And raise them in /etc/security/limits.conf or /etc/security/limits.d/*conf

1
  • I have raised soft and hard nofile limits from 1024/4096 to 16384/32768 but still hitting the 1024 listening ports limit. – loloy.batoytoy Feb 8 '15 at 0:27
0

By the way I didn't mention that the program/script is launched by xinetd, and that xinetd is ignoring the ulimit nofile settings, looking at the xinetd source now to try and bypass this limitation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.