How does the web work: DNS lookup

Have ever asked yourself, how does the web work? I'd like to provide a hopefully quick overview of what goes on behind the scenes when you access a web page. Whether you are a seasoned developer or just starting out, I hope that you'll find something useful in this post.

Architecture

One of the most known software architecture patterns around is client-server. A client can be a laptop, a mobile phone or even a fridge. Clients request data. A server on the other hand responds with data.

A client uses a piece of software (a web browser) to talk to servers and shows results of this. A server is just another computer that helps process, store and serve data.

So what actually happens in this request-response cycle? We are going to take a closer look at this.

This post will be about one of the most important parts of the cycle (and internet in general) - DNS (Domain Name System). This system was proposed by a computer scientist Paul Mockapetris in 1983. It is an essential component of the internet.

So let's start at the very beginning.

DNS Lookup

It is difficult for us humans to remember long, random sequences of numbers (in this particular case IP addresses), hence we use domain names. However, a browser does not understand what www.bbc.co.uk is and what to do with it. It needs an IP address to navigate to.

As a matter of fact, every domain name has an associated IP address. This is one of the reasons why DNS (Domain Name System) exist. DNS servers store information about domains such as where to find them and their associated IP addresses. Think of it as a phone book, there are names and associated phone numbers.

Cache

A number of things happen when you type in a URL in the browser (e.g. https://www.bbc.co.uk) and press the return (enter) key.

If you recently visited www.bbc.co.uk, the IP address of the website might still be stored in your browser cache. The browser will check there first. If it does not find anything, it will check operating system cache.

Still nothing? Some routers cache DNS records too, so another check will be carried out there.

What if there are no records in the browser, operating system and router? Then the operating system is configured to ask the recursive name server (also known as resolving name server). The recursive name server is usually configured by your ISP (internet service provider) but can also be configured manually.

Recursive name server

The recursive name server is the workhorse of the DNS. There is a good chance that it will have the DNS record you are querying for cached locally. If it does then it will return the result. If it doesn't it will ask the root name servers. All recursive name servers should know about is where to find the root name servers.

Root name servers

Recursive name server asks the root name servers for the IP of www.bbc.co.uk. Root name servers are the first step in resolving a domain. There are 13 of these in the world, majority of which are located in the United States.

Root name servers do not know where to find the exact IP address but they are aware of the location of top level domain (.com, .co.uk, .org, .net, etc.) servers. In our example it will be the location of co.uk TLD servers. Recursive name server then takes that information, caches it and queries the TLD servers.

TLD servers

Recursive name server asks the co.uk TLD servers for the IP address of www.bbc.co.uk. The TLD servers do not know the exact IP but provide information about the authoritative name servers for www.bbc.co.uk. The recursive name server caches the response and goes to the authoritative name servers.

With the help of the domain registrars, the TLD servers know which authoritative name servers to use. Domain registrars manage domain name registrations. When a domain gets purchased, the registrars know which name servers to use. They then update the registry.

The registry is the organisation that is responsible for the top level domain (in our case co.uk) servers therefore it updates the TLD servers.

Authoritative name servers

Recursive name server finally asks the authoritative name servers for the IP address of www.bbc.co.uk. The authoritative name servers reply with the exact IP address.

The Recursive name server then takes the data, caches it and returns the result to the operating system. The operating system passes the IP to the browser and the browser makes a connection with the IP. Job done!

Final words

Now, this was a very compressed and high-level overview of the DNS and DNS lookup process. You should definitely do more research if you want to get more detailed about it. Remember that DNS is one of the core part of the internet and I believe that it is really useful to know how it works at least on a basic level.

Until next time!


830 Words

May 23, 2019