Is there a way for non-root processes to bind to “privileged” ports on Linux?

后端 未结 24 1310
予麋鹿
予麋鹿 2020-11-22 02:04

It\'s very annoying to have this limitation on my development box, when there won\'t ever be any users other than me.

I\'m aware of the standard workarounds, but non

24条回答
  •  北荒
    北荒 (楼主)
    2020-11-22 02:43

    Two other simple possibilities:

    There is an old (unfashionable) solution to the "a daemon that binds on a low port and hands control to your daemon". It's called inetd (or xinetd). The cons are:

    • your daemon needs to talk on stdin/stdout (if you don't control the daemon -- if you don't have the source -- then this is perhaps a showstopper, although some services may have an inetd-compatibility flag)
    • a new daemon process is forked for every connection
    • it's one extra link in the chain

    Pros:

    • available on any old UNIX
    • once your sysadmin has set up the config, you're good to go about your development (when you re-build your daemon, might you lose setcap capabilities? And then you'll have to go back to your admin "please sir...")
    • daemon doesn't have to worry about that networking stuff, just has to talk on stdin/stdout
    • can configure to execute your daemon as a non-root user, as requested

    Another alternative: a hacked-up proxy (netcat or even something more robust) from the privileged port to some arbitrary high-numbered port where you can run your target daemon. (Netcat is obviously not a production solution, but "just my dev box", right?). This way you could continue to use a network-capable version of your server, would only need root/sudo to start proxy (at boot), wouldn't be relying on complex/potentially fragile capabilities.

提交回复
热议问题