8

I installed easyPHP and opened a port on my firewall so that other people can access to my webserver. The default port is 8888. But I am wondering how do you choose a port number? Is it really ambiguous or there is a "prefered" range of port number?

3

1 Answer 1

23

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:

  1. (On Unix based systems at least), only root can bind to ports below 1024.
  2. You ideally don't want a port typically associated with another common service as this can cause problems with some firewalls.
  3. 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.

9
  • 1
    On modern Windows versions you have to have administrator privileges in order to bind to ports below 1024 as well.
    – enkryptor
    Commented Jul 24, 2018 at 9:54
  • @enkryptor: Which versions are those? Is this documented anywhere? Commented Jul 24, 2018 at 13:25
  • @grawity I believe it's Windows 7 and later. You can also give a permission to a non-admin user for a specific url via netsh http add urlacl
    – enkryptor
    Commented Jul 24, 2018 at 13:31
  • @enkryptor I have nginx running on port 80, non-localhost ip, and I'm not admin in this system.
    – Braiam
    Commented Jul 24, 2018 at 13:52
  • @Braiam good for you
    – enkryptor
    Commented Jul 24, 2018 at 13:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .