How does a url know which server it needs to reach?

4

I was wondering what happens when we type a url like http://www.mydomain.com ? How does it know where to go to get the pages of mydomain.com? How does all this happen?

OM The Eternity

Posted 2012-01-06T05:14:49.053

Reputation: 143

Why the downovtes? It's a very basic question but I don't see anything particularly wrong with it. – None – 2012-01-06T08:30:54.313

1I didn't downvote it, but it's not clear how much detail the OP wants (and whether they even know that this is a very wide open question). Do the just want an explanation of DNS? Routing? TCP? – None – 2012-01-06T11:25:17.577

Answers

8

An URL is just an address, a reference. So here is how it is happening:

  1. the user enters the URL in the browser. This is handled by the keyboard driver that will send keyboard events to the browser, that will respond by updating the address bar with the typed characters
  2. the browser parse the URL in various parts as defined by RFC 3986
  3. the browser select the host part and it will use the internal resolver library to find the IP address. The most used resolver is DNS. For this the resolver library that is mapped inside the application will make a UDP request on port 53 on the DNS server configured for the client machine. The DNS server will search for the request in the internal cache and if it is expired or missing it will make a recursive request trying to find the address.
  4. the browser connects to the HTTP server on the default port (TCP/80).
  5. the browser sends a GET request and specifies also a HOST header as per HTTP/1.1 see RFC 2616
  6. the http server will parse the request and dispatch the request to the virtual host specified in the request
  7. the application return the generated content (usually a HTML) to the browser
  8. the browser parse the result, generate some JavaScript/DOM events, and renders the page (e.g. Gecko engine in FireFox).

This is a very very condensed explication. I do not speak about SSL, compression, language and character encoding negotiation, authentication, CGI, pipe-lining and keep-alives.

Mircea Vutcovici

Posted 2012-01-06T05:14:49.053

Reputation: 431

@nickgrim That's more the fault of a poorly written question. – Shadur – 2014-09-11T07:03:37.410

isnt there any role of DNS and ISP in it? – OM The Eternity – 2012-01-06T05:43:02.850

DNS is, usually, used by resolver library for gethostbyname() call to translate from hostnames to IP addresses. – Mircea Vutcovici – 2012-01-06T05:54:52.423

ISP is used on the OSI layers bellow TCP. – Mircea Vutcovici – 2012-01-06T05:55:46.773

To understand what is happening use a network sniffer like Wireshark and a HTTP debug proxy like Fiddler – Mircea Vutcovici – 2012-01-06T05:57:58.537

I downvoted this. It's a detailed answer, but I don't think it's an answer to what the OP's actually asking. It seems like the OP's after an explanation of DNS and you sort of skipped over that in your step 3. – None – 2012-01-06T11:24:47.407

Well, you can write an entire encyclopedia just to explain all details for a "simple" thing like a HTTP request. – Mircea Vutcovici – 2012-01-06T13:56:39.333