1

I've got multiple services running on consecutive ports (listening on them) in urestricted range (1024+). From time to time I need to restart those services and it happens that one of services is using port of other service as local port to connect to database. In a result other service complains about not being able to listen on now-busy-port. I need to manually determine service with netstat to force port change by restarting this very service so port is now free to use by rightfull other service.

Is there any method to prevent port from being used as opening and allowing it to be opened in listen mode only?

System: Linux

Currently using port range from 9000-9100

2
  • What OS are you using, and which ports do you need (i.e. how high are they in the range)? Commented Jul 25, 2019 at 11:52
  • @grawity: linux, ports are from range 9000-9100. I've updated my question with this info.
    – DevilaN
    Commented Jul 25, 2019 at 11:56

1 Answer 1

2

Normally these ports should already be outside of the "ephemeral" port range (which is not the same as unprivileged ports). The range is set by the net.ipv4.ip_local_port_range sysctl, and on my system it shows 32768–60999 by default.

If the local_port_range is high enough, it means that port 9000 should never get automatically chosen as the source port (although it doesn't stop programs from explicitly binding to this port).

You can also add your ports to the net.ipv4.ip_local_reserved_ports sysctl (via /etc/sysctl.d); this option takes a space-separated list of individual port numbers.

1
  • On my gentoo there is no default value (sysctl result is empty for this variable). Your answer seems to nail it. Thank you very much!
    – DevilaN
    Commented Jul 25, 2019 at 17:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .