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.
-
1This is better answered here: http://stackoverflow.com/questions/10476987/best-tcp-port-number-range-for-internal-applications – matt2000 Oct 21 '14 at 12:29
12 Answers
Go here and pick a port with the description Unassigned

- 14,656
- 11
- 42
- 52
-
16
-
4
-
2If all developers go by that logic it would mean that all new services gather around the few unassigned ports. What would the probability be that a service is running on an assigned port vs an unassigned port. (Sorry if I'm not exposing some trade secret :) – hultqvist Aug 23 '17 at 14:11
-
1If you are looking for a port to use on an internal network then please consider this answer on a similar question: https://stackoverflow.com/questions/218839/assigning-tcp-ip-ports-for-in-house-application-use/38141340#38141340 – adrianwadey May 29 '19 at 10:33
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

- 19,950
- 4
- 55
- 71
-
10But wouldn't using a dynamic port leave me open to intermittent (although rare) port conflicts? Perhaps it is safer to use a port in the registered range that is unassigned or assigned to an obscure app. – Kevin Wong Sep 25 '08 at 15:21
-
4unless you explicitly register your port choice with IANA, you run the same conflict odds using an "UNASSIGNED" I would think. Actually since there are many unassigned's in the low end, those probably would be more likely IMHO – curtisk Sep 25 '08 at 15:25
-
2Always start with the unassigned range, with the option of a user/admin configurable port to deal with possible conflicts. ONLY if your application reaches broad use (think BitTorrent, or some other large usage) should you really consider applying for an assigned port. Otherwise stay out of the assigned range. If this is for something strictly internal/personal then simply document the ports in use by various services and you should be fine so long as people can look them up somewhere online. Think of the private/dynamic range similar to non-routable IPs - they perfect for small/private use. – jefflunt Aug 16 '13 at 14:37
-
3Just don't make the mistake of assuming your app needs an IANA assigned port because you think your app will explode in usage before it actually does. :) – jefflunt Aug 16 '13 at 14:38
-
9Regarding the dynamic range, I think the "conflict" question may have been asking whether, if an OS is using that range for ephemeral ports (as it should), would that run into a conflict with the port you chose if the OS randomly decides to use that port for e.g. some outbound connection. (Random use of this range is what ephemeral ports are for, as I understand it.) See this other [question](http://stackoverflow.com/questions/10476987/best-tcp-port-number-range-for-internal-applications) which states the concern in more detail. – Garret Wilson Nov 14 '13 at 18:13
-
The dynamic range is a bad idea. We used one port in that range and have had dns.exe conflict too many times. – hultqvist Aug 23 '17 at 14:05
The most comprehensive list of official IANA port numbers and non-official port numbers I know is nmap-services.

- 10,038
- 6
- 38
- 54
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.

- 23
- 3

- 2,509
- 1
- 16
- 26
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.
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.

- 56,086
- 21
- 82
- 121
If this is for an application that you expect to be used widely, then register a number here 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.

- 5,588
- 2
- 27
- 25
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.

- 108,003
- 19
- 148
- 163
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.

- 9,302
- 2
- 26
- 22
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.

- 364
- 3
- 7