# DNS Resolution Process

> How the internet translates a human-readable domain name into an IP address.

Subject: Internet | Lesson 6 of 35 | 4 min read
Interactive lesson: https://codewithanimation.in/internet/dns-resolution-process
Previous: [Domain Names](https://codewithanimation.in/internet/domain-names.md) | Next: [Client-Server Architecture](https://codewithanimation.in/internet/client-server-architecture.md)

## What is DNS?

The **Domain Name System (DNS)** is the phonebook of the internet.

When you type `google.com` into your browser, the browser has no idea where that is. It needs the underlying IP address (like `142.250.190.46`). DNS is the exact step-by-step process of looking up that 'phone number'.

## Why Developers Need It

Every time a user visits your app or your frontend calls an API, a DNS resolution occurs. This lookup takes time (latency).

If you misconfigure your domain's DNS records (like A records or CNAME records) when deploying your app, your website will literally disappear from the internet. Additionally, understanding DNS caching is critical when you move your app to a new server, as some users might still be directed to the old IP address for up to 48 hours.

## The 4-Step Resolution Journey

DNS resolution is a relay race involving four different servers:

**1. The Recursive Resolver:** Your ISP's server. Your browser asks it for the IP. If it doesn't have it cached, it goes on a hunt.

**2. The Root Server:** The Resolver asks the Root Server, 'Hey, who knows about `.com`?' The Root points to the TLD server.

**3. The TLD Server:** The Resolver asks the `.com` server, 'Who knows about `google.com`?' The TLD points to the Authoritative Name Server.

**4. The Authoritative Name Server:** The Resolver asks it for the IP. This server actually holds the final 'A Record' (the IP address). The Resolver brings this IP back to your browser!

## Common mistake: The TTL (Time To Live) Trap

A common pain point when launching a new website is DNS Propagation delay. Every DNS record has a TTL (Time To Live), which tells resolvers how long to cache the IP address. If your TTL is set to 24 hours, and you change your server's IP, users around the world will still be sent to the dead, old IP for a full day!

## Tip: Lower TTL Before Migrating

Pro tip: If you plan to move your database or web app to a new server IP, lower your DNS TTL to 5 minutes at least two days before the move. This ensures the internet updates almost instantly when you flip the switch.

## Try it: The DNS Relay Race

Click 'Resolve' to watch how your browser talks to the four different servers in real-time to find the IP address for google.com.

The animation is on the lesson page and is not part of this text version: https://codewithanimation.in/internet/dns-resolution-process

## Check yourself

### Question 1

What is the primary role of the Authoritative Name Server?

- A. To cache all IP addresses for your local neighborhood.
- B. To provide the final, official IP address (A record) for a specific domain.
- C. To block malicious domains from loading.
- D. To generate the HTML for the website.

Correct answer: B

The Authoritative Name Server is the final stop in the DNS lookup process. It holds the actual DNS records (like A records and CNAMEs) configured by the domain owner.

- Why not A: That is the job of the Recursive Resolver (usually run by your ISP).
- Why not C: While some DNS resolvers filter malware, the Authoritative Server's only job is to answer queries for its specific domain.
- Why not D: DNS servers only provide IP addresses, not HTML. The Web Server provides the HTML.

### Question 2

Why might a user still see your old website after you updated your DNS to point to a new server IP?

- A. Because the old server is intentionally overriding the new one.
- B. Because their local Recursive Resolver cached the old IP address based on the previous TTL (Time To Live).
- C. Because they need to buy a new domain name.
- D. Because IPv6 takes longer to update than IPv4.

Correct answer: B

DNS caching is a double-edged sword. It makes the internet incredibly fast, but if a cached record hasn't expired (reached its TTL limit), the resolver will continue handing out the old, stale IP address.

- Why not A: Servers don't control DNS routing; they only respond when traffic arrives.
- Why not C: The domain name stays the same; only the underlying IP address changed.
- Why not D: DNS resolution times and caching rules apply equally to IPv4 and IPv6.

### Question 3

In the DNS lookup process, which server does the Recursive Resolver ask first?

- A. The Root Server
- B. The TLD (Top-Level Domain) Server
- C. The Authoritative Name Server
- D. The Web Server

Correct answer: A

If the Recursive Resolver doesn't have the IP cached, it starts at the very top of the hierarchy: the Root Server (which points it to the TLD Server, which points it to the Authoritative Server).

- Why not B: The Resolver must first ask the Root Server to find out where the TLD server is located.
- Why not C: This is the very last server queried in the chain.
- Why not D: The Web Server isn't part of DNS. You only talk to the Web Server after DNS gives you the IP.

## Remember this

- DNS is the phonebook of the internet, translating domains to IP addresses.
- The lookup sequence: Browser -> Resolver -> Root -> TLD -> Authoritative.
- DNS records are cached based on their TTL (Time To Live) to speed up future lookups.
