How to choose open port number?
Solution 1:
A port number is a 16-bit unsigned integer, thus ranging from 0 to 65535 (although 0 cannot be used for TCP; it has a special meaning for UDP).
You can use pretty much any port number in the range, however there are some guiding rules:
- (On Unix based systems at least), only root can bind to ports below 1024.
- You ideally don't want a port typically associated with another common service as this can cause problems with some firewalls.
- Expanding on (2) above - On Linux systems at least, there is a file
/etc/services
which has a list of common services - you can use this for guidance.
The "ideal" port to run an HTTP service is port 80, and the ideal port for HTTPS is 443, because those ports are associated with their respective services. If this is not practical (and it often isn't - some routers are too stupid to handle a web interface and port forward externally on the same port), it's common to pick a "themed" port - port 8080 is pretty common, as is port 8000.