I have written an application that will run on an embedded device. The installation is very minimal and uses busybox and not many other things. Part of the software includes a listener thread that accepts incoming TCP/IP connections. The port number I used does not exist within the devices /etc/services file so I know this port is available, but I am wondering if I need to register this port in some way so that no other utilities are able to use it? Is there anything explicit I need to do myself to register a listening port or will the socket system functions deal with all of this for me behind the scenes? Or does the fact that the port I wish to use is not present in /etc/services mean that I do not have to worry at all about this aspect of my application?

  • 2
    No. If you are distributing the application the port should be configurable. If not you can use any port you know isn't actually in use -- you don't have to avoid everything in /etc/services. Eg, if you know for sure the device will not be running a quake server, go ahead and use port 666. It must be able to distinguish legitimate from illegitimate/accidental/whatever calls anyway, otherwise it is very fragile indeed. – goldilocks Mar 20 '13 at 12:17

/etc/services is only used for service name resolution. Unless you want to refer to your port by name, there's no need to update the file. However, you might want to add it anyway, if only for your own sanity.

A few things you might want to consider when selecting your port number:

  • Only root can bind to a port <1024. This is to protect sensitive system ports (e.g. port 22 for ssh) being compromised by opportunistic user processes.
  • Ports >=32768 can be allocated dynamically by the system, generally for outgoing connections.

If your code successfully binds to the port, no other non-root processes can use it.

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.