Re:Port 0: The Port That Does Not Exist
by 99harry on Saturday November 07, 2026 @08:43AM
(#50404468)
Sometimes I have scripts that automatically assign ports starting from 30000. How would that work? Would I have to bind to port 0 multiple times until I randomly get a port in that range?
[ Parent
| on HN ]
Re:Port 0: The Port That Does Not Exist
by 0bytes on Saturday November 07, 2026 @09:25AM
(#50404813)
I’m not exactly sure if that’s the question, but the range can be set. Here’s the Linux solution: https://tldp.org/LDP/solrhe/Securing-Optimizing-Linux-RH-Edi...
FreeBSD has net.inet.ip.portrange
Re:Port 0: The Port That Does Not Exist
by 99harry on Saturday November 07, 2026 @10:12AM
(#50405234)
That might not quite fit my use case. My AI-generated scripts probably won't modify system-level configuration files to change the port range
Re:Port 0: The Port That Does Not Exist
by Zambyte on Saturday November 07, 2026 @10:43AM
(#50405482)
... do you not have a say in the matter?
I'm not quite sure what a script assigning ports actually does, but if I need an app to bind a port in some port range, I just start binding ports starting from 30000 until it succeeds.
If it's in a script then that might be difficult, but a racy approximation could be to loop e.g. listening socat with different ports for finding the free port. (Or maybe: parse output of ss.) But if the port use is separate from the port binding, then it might still be busy once the time to rebind it comes.