How Does a DNS Query Work? The Full Path From Browser to IP Address

Understand the life of a DNS query in this complete step-by-step guide with a visual diagram. Learn how your browser converts domain names into IP addresses, what DNS resolution is, and how DNS servers interact to load websites. Explore caching, recursive vs. iterative queries, and DNS security techniques like DNSSEC, DoH, and DoT — all explained in an easy-to-follow format ideal for students, tech professionals, and curious learners.

Jun 18, 2025 - 10:06
Updated: 8 days ago
106.7k
How Does a DNS Query Work? The Full Path From Browser to IP Address

Quick answer: A DNS query turns a domain name into an IP address. Your device checks its caches, then asks a recursive resolver. If the resolver has no cached answer it asks a root server, then the top-level domain server, then the domain's authoritative server, caches the result for its TTL and returns the IP address to you.

Key takeaways

  • The stub resolver on your device asks a recursive resolver; the resolver does the heavy lifting.
  • The resolver walks the hierarchy: root servers, TLD servers, then the authoritative name server.
  • Caching at every level, controlled by TTL, makes most lookups fast.
  • Recursive means "get me the final answer"; iterative means "tell me who to ask next".
  • You can watch the process with dig +trace, and DNS has security issues such as spoofing that DNSSEC and encrypted DNS address.

What is a DNS query?

Computers locate each other with IP addresses, but people use names such as www.example.com. The Domain Name System (DNS) is the distributed directory that translates names into addresses and other records. A DNS query is a question sent to this system, for example "what is the A record (IPv4 address) of www.example.com?". The protocol is documented in the IETF's DNS standards, which are indexed at the IETF RFC pages.

Who takes part in a DNS lookup?

RoleWhat it does
Stub resolverA small client in your operating system. It asks a recursive resolver and does not walk the hierarchy itself
Recursive resolverRun by your ISP, company or a public DNS provider. It finds the answer for you and caches it
Root serversKnow which servers handle each top-level domain, such as.com or.in
TLD serversKnow which name servers are responsible for each domain in that TLD
Authoritative serversHold the real records for a domain, such as its A and MX records

What happens step by step?

  1. Browser cache. The browser checks whether it already knows the address from a recent lookup.
  2. Operating system cache and hosts file. The system checks its own cache and the local hosts file.
  3. Query to the recursive resolver. The stub resolver sends a recursive query to the configured resolver and waits for a final answer.
  4. Resolver cache. If the resolver has a fresh answer, it returns it immediately. This is the common case.
  5. Ask a root server. If not, the resolver asks a root server about www.example.com. The root does not know the address but replies with a referral: the name servers for .com.
  6. Ask the TLD server. The resolver asks a .com server, which replies with a referral to the authoritative name servers for example.com.
  7. Ask the authoritative server. The resolver asks it for www.example.com and receives the A record, for example an IPv4 address, and a TTL.
  8. Cache and reply. The resolver stores the answer for the TTL and sends it to your device, which also caches it.
  9. Connect. The browser now opens a TCP connection to that address. DNS is finished.

Steps 5 to 7 are iterative queries made by the resolver: each server either answers or points to the next one. Step 3 is a recursive query made by your device, which asks the resolver to deliver the final answer.

What do TTL and caching do?

Every record has a time to live (TTL), in seconds, that tells caches how long to keep it. A TTL of 300 means a change you make may take up to five minutes to reach users who have cached the old value. Caching makes DNS fast and reduces load on authoritative servers. Lower the TTL before a planned migration and raise it afterwards.

How can you watch a DNS query yourself?

These commands only read public DNS data. Use a domain you own or a public one.

dig www.example.com # ask your configured resolver
dig +trace www.example.com # walk from the root down, like a resolver
dig www.example.com @1.1.1.1 # ask a specific resolver
dig NS example.com # which name servers are authoritative
dig +short MX example.com # mail servers

With +trace, the output shows each level in turn: the root server list, the answer from a root server naming the TLD servers, the TLD answer naming the domain's name servers, and finally the authoritative answer with the A record. The line for each answer includes the TTL. Compare two runs a few seconds apart using plain dig and watch the TTL count down, which shows caching at work.

How long does a lookup take?

A cached answer comes back in a few milliseconds. An uncached lookup that walks the hierarchy takes longer and depends on distance to the servers. Because most queries hit a cache, ordinary browsing rarely waits on the full path. Measure with dig, which prints the query time.

What are the DNS security issues?

  • Cache poisoning and spoofing: forged responses could trick a resolver into storing a wrong address. DNSSEC signs records so resolvers can verify them.
  • Eavesdropping: traditional DNS is unencrypted. DNS over HTTPS (DoH) and DNS over TLS (DoT) encrypt the path between you and the resolver.
  • DNS tunnelling and data exfiltration: data hidden in queries. Monitor unusual query volume and long random subdomains.
  • Hijacking: attackers change a domain's name server settings. Protect registrar accounts with MFA and registry locks.
  • DDoS: overloading DNS servers. Use redundancy and anycast.

Common mistakes and misunderstandings

  • Confusing the recursive resolver with the authoritative server.
  • Expecting a DNS change to appear instantly everywhere.
  • Forgetting that the hosts file and caches can override DNS.
  • Assuming HTTPS hides DNS lookups; they are separate unless DoH or DoT is used.

Next steps

For related reading, see DNS and DNSSEC and what happens when you type a URL. To study networking in depth, see our computer networking course.

Frequently Asked Questions

It is a request to the Domain Name System for information about a name, most often its IP address. The answer comes from a cache or, if needed, from the root, TLD and authoritative servers.

DNS translates human-friendly domain names into IP addresses and other records so that devices can find services. It also carries information such as mail server locations and verification text records.

It starts on your device. The browser and operating system check their caches, and if there is no answer, the stub resolver sends a query to the configured recursive resolver.

A recursive query asks the server to find the complete answer on the client's behalf. Your device sends recursive queries to its resolver, which then does the work of contacting other servers.

An iterative query lets the server reply with either the answer or a referral to another server. A recursive resolver uses iterative queries to move from the root to the TLD to the authoritative server.

Use dig +trace followed by a domain name. It shows each stage from the root servers through the TLD servers to the authoritative answer, including the TTL values that control caching.

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Wow Wow 0
Sad Sad 0
Angry Angry 0
Vaishnavi

Vaishnavi is a skilled tech professional at the Ethical Hacking Training Institute in Pune, responsible for managing and optimizing the technical infrastructure that supports advanced cybersecurity education. With deep expertise in network security, backend operations, and system performance, she ensures that practical labs, online modules, and assessments run smoothly and securely. Her behind-the-scenes contributions play a vital role in delivering a seamless and secure learning experience for aspiring ethical hackers.