How should one go about choosing a default TCP/IP port for a new service?

NetworkingTcp

Networking Problem Overview


When developing an app that will listen on a TCP/IP port, how should one go about selecting a default port? Assume that this app will be installed on many computers, and that avoiding port conflicts is desired.

Networking Solutions


Solution 1 - Networking

Go here and pick a port with the description Unassigned

Solution 2 - Networking

First step: look at IANA listing :

There you will see at the tail of the list

"The Dynamic and/or Private Ports are those from 49152 through 65535"

so those would be your better bets, but once you pick one you could always google on it to see if there is a popular enough app that has already "claimed" it

Solution 3 - Networking

If by widely-used, you mean you want to protect against other people using it in the future, you can apply to have it marked as reserved for your app by IANA here

Solution 4 - Networking

The most comprehensive list of official IANA port numbers and non-official port numbers I know is nmap-services.

Solution 5 - Networking

You probably want to avoid using any ports from this list (Wikipedia).

I would just pick one, and once the app is used by the masses, the port number will become recognized and included in such lists.

Solution 6 - Networking

Choosing an unassigned one from the IANA list is usually sufficient, but if you are talking about a commercially-released product, you really should apply to the IANA to get one assigned to you. Note that the process of doing this is simple but slow; the last time I applied for one, it took a year.

Solution 7 - Networking

As others mention, check IANA.

Then check your local systems /etc/services to see if there are some custom ports already in use.

And please, don't hardcode it. Make sure it's configurable, someway, somehow -- if for no other reason that you want to be able to have multiple developers using their own localized builds at the same time.

Solution 8 - Networking

If this is for an application that you expect to be used widely, then register a number [here][1] so no-one else uses it.

Otherwise, just pick an unused one randomly.

The problem with using one in the dynamic range is that it may not be available because it may be being used for a dynamic port number.

[1]: http://www.iana.org/cgi-bin/usr-port-number.pl "here"

Solution 9 - Networking

Well, you can reference some commonly used port numbers here and try not to use anyone else's.

If by "open to the public at large" you mean you're opening ports on your own systems, I'd have a chat with your system administrators about which ports they feel comfortable with doing that with.

Solution 10 - Networking

Choose a number that is not very common

Solution 11 - Networking

Choose a default port that doesn't interfere with the most common daemons and servers. Also make sure that the port number isn't listed as an attack vector for some virus -- some companies have strict policies where they block such ports no matter what. Last but not least, make sure the port number is configurable.

Solution 12 - Networking

Use iana list. Download the csv file from :

https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.csv

and use this shell script for searching for unregistred ports:

for port in {N..M}; do if ! grep -q $port service-names-port-numbers.csv; then echo $port;fi; done;

and put 2 numbers instead of N and M.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKevin WongView Question on Stackoverflow
Solution 1 - NetworkingKevin WongView Answer on Stackoverflow
Solution 2 - NetworkingcurtiskView Answer on Stackoverflow
Solution 3 - Networkingjj33View Answer on Stackoverflow
Solution 4 - NetworkingThorsten79View Answer on Stackoverflow
Solution 5 - NetworkingMike MazurView Answer on Stackoverflow
Solution 6 - NetworkingGraeme PerrowView Answer on Stackoverflow
Solution 7 - NetworkingZathrusView Answer on Stackoverflow
Solution 8 - NetworkingMark BakerView Answer on Stackoverflow
Solution 9 - NetworkingAdam BellaireView Answer on Stackoverflow
Solution 10 - NetworkingdsmView Answer on Stackoverflow
Solution 11 - NetworkingAlexanderView Answer on Stackoverflow
Solution 12 - NetworkingMahdi PerfectView Answer on Stackoverflow