Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
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

1 Answer 1

up vote 5 down vote accepted

/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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.