Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select a static port number for a custom app?

Tags:

linux

port

We've got a custom application that needs to serve requests on it's own port number. We really don't care what the number is, although we'll stick to that port after we decide. How do I select a number which is least likely to conflict with other applications or services that are running on the user's system?

Are there any rules or standards we should follow?

A clarification: once we pick a port, we need to stick with it. Can't use a dynamic one. We're building a custom SFTP server and we'll have to tell our customers what port it's running on.

like image 932
ccleve Avatar asked Sep 01 '11 19:09

ccleve


People also ask

How are port numbers determined?

A port number uniquely identifies a network-based application on a computer. Each application/program is allocated a 16-bit integer port number. This number is assigned automatically by the OS, manually by the user or is set as a default for some popular applications.

What is a reasonable port number?

Dynamic and/or Private Ports (49152-65535): This range is ideal for custom port numbers.

What is the best port number?

The highest TCP port number is 65,535. The TCP protocol provides 16 bits for the port number, and this is interpreted as an unsigned integer; all values are valid, apart from 0, and so the largest port number is (2^16 - 1) or 65,535.


2 Answers

For a static application, consider checking /etc/services to find a port that will not collide with anything else you are using and isn't in common use elsewhere.

$ tail /etc/services
nimspooler      48001/udp                       # Nimbus Spooler
nimhub          48002/tcp                       # Nimbus Hub
nimhub          48002/udp                       # Nimbus Hub
nimgtw          48003/tcp                       # Nimbus Gateway
nimgtw          48003/udp                       # Nimbus Gateway
com-bardac-dw   48556/tcp                       # com-bardac-dw
com-bardac-dw   48556/udp                       # com-bardac-dw
iqobject        48619/tcp                       # iqobject
iqobject        48619/udp                       # iqobject
like image 67
Michael Berkowski Avatar answered Oct 11 '22 02:10

Michael Berkowski


If you can't predict the exact kind of environment your application is going to run, just don't bother with this. Pick any number over 1024 and also make it configurable so the user can change it in case of conflict with another service/application.

Of course you can still avoid very common ports like 8080 (alternative HTTP) or 3128 (proxies like squid), 1666 (perforce), etc. You can check a comprehensive list of known ports here, or take a look at /etc/services.

like image 37
jweyrich Avatar answered Oct 11 '22 04:10

jweyrich