Networking interview questions

Table of Contents

How does DNS work?

The Domain Name System, or DNS, is what allows you to use human-friendly domain names instead of numeric IP addresses. When you type a website name into your browser, DNS is responsible for finding the IP address that the network can actually connect to.

The first place a DNS request goes is the local DNS server, often called a recursive resolver. This server acts as an assistant for your computer. It takes your request and handles all the work needed to find the correct IP address.

Your computer usually learns the address of its local DNS server when it connects to a network. This information is provided automatically through DHCP by your router or network gateway. Along with an IP address and default route, your device is told which DNS server to use for name lookups. In some cases, this can also be configured manually in the network settings.

The local DNS server keeps a cache of recently resolved domain names. If the requested name is already in cache and still valid, the server can return the IP address immediately. This makes most DNS lookups very fast.

If the domain name is not found in cache, the local DNS server must ask other DNS servers for help. It starts at the top of the DNS hierarchy by contacting a root DNS server. Root servers do not know the final IP address, but they know which servers manage each top-level domain.

The root server responds with the address of a Top-Level Domain server, such as those responsible for.com,.org, or country-specific domains. The local DNS server then contacts the TLD server, which points it to the authoritative server for the requested domain.

The authoritative DNS server holds the actual mapping between the domain name and its IP address. Once this server responds, the local DNS server returns the IP address to your computer and stores it in cache for future use.

Iterative DNS query

In an iterative DNS query, each DNS server gives the best answer it has and tells the resolver where to go next. No server completes the lookup on its own. Instead, the local DNS server follows the referrals step by step until it reaches the authoritative server.

This means the local DNS server does most of the work, contacting the root server, then the TLD server, and finally the authoritative server before returning the result to the client.

Iterative DNS resolution flow

Recursive DNS query

A recursive DNS query is what your computer sends to the local DNS server. When making this request, your computer expects a final answer and does not want to contact any other DNS servers itself.

The local DNS server handles the entire resolution process on behalf of the client. Once it finds the IP address, it sends the result back and saves it in cache so future requests can be answered more quickly.

Recursive DNS resolution flow