How Does a DNS Query Work? The Full Path From Browser to IP Address
When you type a website name, your browser first checks its own cache, then asks the operating system. If neither has the answer, the OS sends the query to a recursive resolver, usually run by your ISP, company or a public DNS service.
Topic: Networking in IT Infrastructure · Explainer
Quick answer: When you type a website name, your browser first checks its own cache, then asks the operating system. If neither has the answer, the OS sends the query to a recursive resolver, usually run by your ISP, company or a public DNS service. The resolver asks a root server which servers handle the top-level domain, such as .com or .in, then asks those TLD servers which servers are authoritative for the domain, and finally asks the authoritative server for the IP address. The answer travels back, every layer caches it for its TTL, and the browser connects to the IP.
Key takeaways
- Most lookups end early because a cache already has the answer.
- The recursive resolver does the legwork; your device only asks one question.
- Root and TLD servers give referrals, not final answers.
- The authoritative server holds the real record and sets its TTL.
- Each step is a place where DNS can be attacked, and defended.
Table of Contents
- Who Takes Part in a DNS Query?
- What Happens on Your Own Device First?
- What Are the Steps of a Full Recursive Lookup?
- How Do TTL and Caching Speed Things Up?
- How Can You Watch a DNS Query Yourself?
- Where Can a DNS Query Be Attacked?
- How Do DNSSEC and Encrypted DNS Protect the Query?
- References
Who Takes Part in a DNS Query?
| Component | Role |
|---|---|
| Stub resolver | Small client in your OS that sends the question |
| Recursive resolver | Chases the answer on your behalf and caches it |
| Root servers | Point to TLD servers; 13 named identities, A to M, run on many anycast sites |
| TLD servers | Point to the authoritative servers for a domain under .com, .in and others |
| Authoritative server | Holds the domain's records and gives the final answer |
The terms follow RFC 9499, and the root server list is kept by IANA.
What Happens on Your Own Device First?
- The browser checks its own DNS cache.
- The OS checks its cache and the hosts file.
- If there is still no answer, the stub resolver sends a recursive query, normally over UDP port 53, to the configured resolver.
What Are the Steps of a Full Recursive Lookup?
Imagine the resolver has an empty cache and you ask for www.example.com. The process is described in RFC 1034 and RFC 1035.
| Step | Who asks whom | Reply |
|---|---|---|
| 1 | Your device to the recursive resolver | Resolver starts working |
| 2 | Resolver to a root server | Referral: here are the .com servers |
| 3 | Resolver to a .com TLD server | Referral: here are example.com's name servers |
| 4 | Resolver to example.com's authoritative server | Answer: the A or AAAA record with a TTL |
| 5 | Resolver to your device | Final IP address, now cached |
| 6 | Browser to that IP | TCP or QUIC connection, then HTTPS |
Steps 2 to 4 are iterative queries: each server either answers or refers the resolver onward. If the name does not exist, the authoritative server returns NXDOMAIN, which is also cached for a time under RFC 2308.
How Do TTL and Caching Speed Things Up?
Every record has a time to live (TTL) in seconds, set by the domain owner. Until it expires, the resolver answers from memory without contacting root, TLD or authoritative servers. Root and TLD referrals have long TTLs, so a busy resolver rarely asks the root at all. Short TTLs make changes spread faster; long TTLs reduce load. This is why a DNS change can take a while to be seen everywhere.
How Can You Watch a DNS Query Yourself?
# follow the referral chain from the root (Linux or macOS)
dig +trace www.example.com
# ask your resolver and show the TTL
dig www.example.com A
# Windows
nslookup www.example.com
ipconfig /displaydns
Resolve-DnsName www.example.com
Running dig twice shows the TTL counting down, proof that the answer came from cache.
Where Can a DNS Query Be Attacked?
- On the device: malware edits the hosts file or DNS settings.
- On the network: plain DNS is readable and can be spoofed on a shared Wi-Fi.
- At the resolver: cache poisoning inserts a false record for many users.
- At the domain: stolen registrar accounts let attackers change name servers.
- As a channel: malware hides data in DNS queries (tunnelling).
How Do DNSSEC and Encrypted DNS Protect the Query?
DNSSEC adds digital signatures so a validating resolver can tell whether records were altered. It proves authenticity but does not hide the query. Encrypted transports such as DNS over HTTPS (RFC 8484) and DNS over TLS hide queries from on-path observers. CISA guidance recommends that organisations use encrypted DNS to a trusted, filtering resolver while keeping DNS logs, which also helps meet CERT-In's 180-day log retention rule. Turn on registrar lock and multi-factor authentication for your domains.
For the bigger picture of records and zones, read our complete guide to DNS, and learn how poisoning works in DNS poisoning explained. Our networking and cybersecurity training includes DNS labs.
References
Frequently Asked Questions
What's Your Reaction?
Like
0
Dislike
0
Love
0
Funny
0
Wow
0
Sad
0
Angry
0