2

I am working with an application that utilizes a port below 1024 because it was originally intended to be run as root. I would like to debug the app in an IDE which I open as myself (non-root user) but I do have sudo privileges. I have reasons against remote debugging as well as opening the IDE under sudo.

So the only way for me to do this would be to allow a non-root user to use ports or a port below 1024. Can that be done and how?

3

If you can't change your app to use a port above 1024 then the easiest way would be to take the port it is using and map it to a port above 1024.

You can do that using the firewall, ipfw is the tool for setting the firewall. You could also do it using 'nc' - sometimes known as ncat or netcat.

There is a question here that gives more details. The thread also mentions "AuthBind" which is an open source package to that allows just this - opening ports below 1024 without granting root privileges.

  • I could tell my app to use a port above 1024 but it would require config changes between my local environment and the source code coming from the VC repository -- that's why i am trying to avoid it – amphibient Jan 30 '14 at 0:32
  • I hadn't thought of the ipfw method, definitely like that better than the netcat solution for not introducing additional complexity with connection handling. – drfrogsplat Jan 30 '14 at 0:45
3

Caveat: If your debugging only requires a single connection, and you don't need to specifically debug connect/disconnect events...

You could use netcat (or nc on some systems).

You set your application to open, say, port 12345 (user-openable). Then you use netcat to open, say, port 123 (privileged-users-only) and forward the data to port 12345.

# sudo nc -l 123 | nc localhost 12345

The first half of the command runs netcat nc and tells it to listen -l on port 123. The pipe redirects data from the first netcat instance to another one. The second command connects to your application and forwards the data through.

Note that as soon as you run this command, the second instance of netcat will connect to your application. If your application is going to start pushing out data immediately, you will want to connect your client very quickly, and will need to be careful about how data is buffered.

If you want the client to be able to disconnect and reconnect without having to restart netcat, then instead run:

# sudo nc -lk 123 | nc localhost 12345

The -k tells netcat to keep running if the client disconnects from port 123.

Again, there's limitations with this method, as you're largely giving up control of the connection side of things by having netcat handle it for you. On the other hand, it's very quick and easy to set up and tear down, if that's all you need.

  • I could tell my app to use a port above 1024 but it would require config changes between my local environment and the source code coming from the VC repository -- that's why i am trying to avoid it – amphibient Jan 30 '14 at 0:31
  • Or the addition of a command-line argument that overrides the configured port or which config file is used. IDEs can typically run with a specific command line, which you wouldn't otherwise use when running as the real service. – drfrogsplat Jan 30 '14 at 0:42

You must log in to answer this question.

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