0

Suppose I have a Vanilla machine and this is the first time I am connecting it to Internet. There is no Cache at any level. I access a website through browser by typing example.com (no http//: or https//:). The first thing that will happen is that machine will resolve the domain name to IP and then a TCP Handshake will take place. There is no port negotiation that has happened yet then how does the browser knows which port to connect to?

I have gone through some articles on the web which states that HSTS will tell the browser which port to use as per the HTTP directive. But this does not explains how the browser decides on the port that it needs to connect to initially? How does the machine's OS knows which traffic is this (ICMP or HTTP). Is it always going to connect on port 80 or some other port first and then the sever would be able to tell which port it will listen on?

2
  • By the way, you didn't read the explanation for your original tag port-security, which has nothing to do with transport protocol ports. I fixed the tags.
    – Ron Maupin
    Aug 31, 2019 at 4:48
  • Did any answer help you? If so, you should accept the answer so that the question doesn't keep popping up forever, looking for an answer. Alternatively, you can provide and accept your own answer.
    – Ron Maupin
    Jul 10, 2020 at 2:45

1 Answer 1

1

There are registered, well-known port numbers for services and transport protocols that use port numbers as transport addresses.

But this does not explains how the browser decides on the port that it needs to connect to initially?

HTTP, by default, uses TCP at the registered, well-known port number 80, and HTTPS, by default, uses TCP at the registered, well-known port number 443. The browser defaults to the default transport protocol and registered, well-known port number for the browser protocol in use. If the server is listening at a different port number, this can be overridden in the URI by appending :<port number> to the FQDN. For example, http://www.example.com:12345.

How does the machine's OS knows which traffic is this (ICMP or HTTP).

The protocol is at the beginning of the URI, e.g. http://, https://, ftp://, etc.

Is it always going to connect on port 80 or some other port first and then the sever would be able to tell which port it will listen on?

The browser will connect (or not if the server is not listening at what the browser tries) based on the URI.


The registered port numbers are maintained by IANA in the Service Name and Transport Protocol Port Number Registry.

9
  • Note that I am not telling the browser that it needs to go to port 80 or 443( http or httsp). I am just typing example.com without any protoco in the browserl. What is the default port that browser will try and connect to? Aug 31, 2019 at 4:41
  • 1
    The browser will have a default protocol. If you type example.com, you will get http:// or https:// in the URI. In any case, applications, such as browsers, are explicitly off-topic here, and various browsers can have various defaults. My answer tries to stick to the transport protocol, and the idea that different services have different registered, well-known port numbers.
    – Ron Maupin
    Aug 31, 2019 at 4:44
  • 1
    The OS doesn't care about the protocol, that's for the application to decide.
    – Zac67
    Aug 31, 2019 at 7:39
  • @Zac67, by any chance do you happen to know what would the default ports in case of browser? Sep 1, 2019 at 15:15
  • See your post above: HTTP defaults to port 80, HTTPS to 443.
    – Zac67
    Sep 1, 2019 at 15:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.