Networking and resource loading

DNS, Domain Name System

A high-level overview of how DNS, the Domain Name System, maps domain names to IP addresses through a tree of servers starting at the root DNS server.

You don’t usually reach a website using its IP address. You can, but it’s rare.

You use a domain name. Like google.com, or flaviocopes.com.

This is handy. I can change the server and the company I use to host a website, and the domain name stays the same. Nobody has to update their bookmarks.

The system that maps domain names to IP addresses is called DNS, the Domain Name System.

A network of servers

DNS is a network of servers. Your internet provider runs its own DNS servers, and your router comes preconfigured to use them.

You can also pick a different one. Google runs a public DNS server at 8.8.8.8, and Cloudflare runs one at 1.1.1.1.

Those servers receive the requests from your computer. If they don’t know the answer, they ask their own reference DNS servers.

A tree

The system is organized like a tree. At the top there is the root DNS server.

To simplify, the root knows the IP addresses of the DNS servers that manage each domain extension: com, net, org, the country-specific ones like it, and the newer ones like blog, dev or tech.

Those servers know where to find the name servers of every domain under their extension. And the name servers of a domain know the actual IP address of flaviocopes.com.

So a lookup walks down the tree: root, then .com, then the name servers of the domain, then the answer.

Of course the real system adds caching, redundancy, and enough capacity to handle huge numbers of concurrent requests. But this is the general idea.

Watch a lookup happen

You can watch a lookup happen with dig:

dig flaviocopes.com +short

It prints one or more IP addresses. Run it again and the answer comes back almost instantly, because your resolver cached it the first time.

If you want to understand the actual records behind a domain (A, CNAME, MX, TXT and so on), I built a free DNS records explainer that walks you through them.

Lesson completed