DNS & Domain Names

What Happens During a DNS Lookup

Follow one DNS query from your browser to the authoritative server and back, and learn where delays and failures creep in.

Key takeaways

  • Your browser and operating system check local caches and the hosts file before sending any query.
  • A recursive resolver does the multi-step search and returns one finished answer to your device.
  • Each step above the final one returns a referral that points closer to the authoritative server.
  • Both successful answers and "does not exist" answers are cached, which explains many delayed fixes.

A DNS lookup is a search for the data behind a name. Your device first checks what it already remembers. If that fails, it asks a resolver, and the resolver follows referrals from the root of the DNS tree down to the server that holds the official answer. Then the result travels back and gets cached along the way.

Most lookups finish in a few milliseconds because some cache already has the answer. The full journey happens only when nothing along the path remembers it, and that journey is worth knowing, because each stop is a place where things can go wrong.

Step zero: checking what is already known

Before any packet leaves your computer, several local sources get a chance to answer.

  1. The browser cache. Browsers keep recently resolved names for a short while.
  2. The operating system cache. Windows, macOS and many Linux setups remember answers so other programs can reuse them.
  3. The hosts file. A plain text file on the device can pin a name to an address, overriding DNS. See the hosts file.

Exact ordering varies by system, and a browser using encrypted DNS may talk to its own chosen resolver. If one of these sources has a usable answer, the lookup is over.

Who can answer before the internet is asked?
Does the browser still remember this name? YES It uses the cached address and connects right away. 1 NO Does the operating system or hosts file have it? YES The system returns that address without sending a query. 2 NO Does the recursive resolver have a fresh copy? YES It replies from cache, usually very quickly. 3 NO Full lookup The resolver walks the DNS tree, starting as high as it needs to. Does the browser still remember this name? 1 IF YES It uses the cached address and connects right away. NO Does the operating system or hosts file have it? 2 IF YES The system returns that address without sending a query. NO Does the recursive resolver have a fresh copy? 3 IF YES It replies from cache, usually very quickly. NO Full lookup The resolver walks the DNS tree, starting as high as it needs to.

The question your device sends

If nothing local helps, the system's stub resolver sends a query to the configured DNS server. The question is small and has three important parts:

  • the name, such as www.example.com
  • the type of record wanted, such as A for IPv4 or AAAA for IPv6
  • the class, which is nearly always IN for internet

A device with both IPv4 and IPv6 typically asks for A and AAAA at about the same time. Modern browsers may also ask for an HTTPS record, which describes how to connect to a site; see SVCB and HTTPS records.

The query sets a flag meaning "recursion desired". That asks the server to return a final result and not just a hint. It usually travels over UDP port 53, or over an encrypted channel if you use DNS over HTTPS or TLS.

The walk down the tree

Assume the resolver has an empty cache. It works through the hierarchy from the top.

A full lookup, referral by referral
Device Resolver Root, then TLD Authoritative A record for www.example.com? 1 Root: who handles com? 2 Referral to the com servers 3 TLD: who handles example.com? 4 Referral to its name servers 5 May include their addresses as glue A record for www.example.com? 6 Answer: 192.0.2.10, TTL 3600 7 192.0.2.10 8 Device Resolver Root, then TLD Authoritativ e A record for www.exa mple.com ? 1 Root: who handles com? 2 Referral to the com servers 3 TLD: who handles example.c om? 4 Referral to its name servers 5 May include their addresses as glue A record for www.example.com? 6 Answer: 192.0.2.10, TTL 3600 7 192.0.2.1 0 8

The root

The resolver asks one of the root servers. The root does not know the address of www.example.com. It replies with the names and addresses of the servers for com.

The top-level domain

The resolver asks one of the com servers. The reply lists the name servers that the owner of example.com has registered. This handover is called delegation.

If those name servers have names under the very domain being delegated, such as ns1.example.com, the resolver would be stuck: it needs the domain's servers to find the address of the domain's servers. The parent breaks the loop by including their addresses, known as glue.

If the name servers live under a different domain, the resolver may first have to run a separate lookup to find their addresses. That is one reason some domains resolve a bit more slowly from a cold start.

The authoritative server

Finally the resolver asks one of the domain's name servers. This one has the real data and marks its reply as authoritative. Many resolvers now send each level only as much of the name as it needs, a privacy measure called query name minimization.

Aliases add steps

The answer may be a CNAME record, which says "this name is another name for that one." The resolver must then look up the new name, possibly walking a different branch of the tree.

www.example.com.        3600  IN  CNAME  site.hosting.example.net.
site.hosting.example.net.  60  IN  A     198.51.100.25

The device receives both records together. Each has its own time to live. Long chains of aliases add delay and give more places to break. The rules are covered in CNAME records.

The answer comes back

The resolver caches every useful piece: the com referral, the domain's name servers and the final record. It returns the answer to your device, which caches it too and hands the address to the application.

Only now does the real connection begin. The browser opens a TCP or QUIC connection to that address, sets up encryption and requests the page. The whole chain is described in what happens when you type a URL.

If several addresses come back, the application picks one and may try another if the first does not respond. Browsers commonly race IPv6 and IPv4 attempts so that a broken path on one does not stall the page.

When the answer is "no"

A lookup can end without an address. The response carries a status code.

Status Meaning Common cause
NOERROR with data Success Normal
NOERROR, no data The name exists, but not that record type No AAAA record, for example
NXDOMAIN The name does not exist Typo, missing record, expired domain
SERVFAIL The resolver could not get a valid answer Broken name servers or DNSSEC failure
REFUSED The server declined to answer Query sent to the wrong server

Negative answers are cached as well. If you look up a name before creating its record, your resolver may keep saying it does not exist for a while afterward. Each code is unpacked in NXDOMAIN, SERVFAIL and other errors.

Where time and failures hide

  • Local settings. A wrong DNS server address, a leftover VPN configuration or a stale hosts entry.
  • The path to the resolver. Weak Wi-Fi or packet loss means retries, and each retry waits for a timeout.
  • The resolver itself. Overloaded or misconfigured resolvers answer slowly or not at all.
  • Dead name servers. If one of a domain's listed servers is unreachable, some lookups wait before trying another.
  • Validation errors. With DNSSEC, an expired signature turns a working domain into SERVFAIL on validating resolvers.

How retries and timeouts work

DNS over UDP has no built-in delivery guarantee. If a query or its reply is lost, nothing tells the sender. Instead, the stub resolver waits for a short period, then tries again, often with the next configured server. The recursive resolver does the same with a domain's name servers, moving down the list and remembering which ones answer quickly.

This explains a particular kind of sluggishness. A page that hangs for several seconds and then loads normally can mean that the first DNS server in your list is not responding and the second one is doing all the work. Everything succeeds, just late. Removing or replacing the dead entry fixes it.

Large answers add another wrinkle. If a reply does not fit in the size the client said it could accept over UDP, the server marks it as truncated, and the client repeats the question over TCP. A firewall that permits DNS over UDP but blocks it over TCP can therefore produce failures that affect only certain names, typically those with many records or signatures.

What other people can see

Each stop in a lookup learns something. The resolver sees every name your device asks about, along with your address. Root and top-level domain servers see questions from the resolver, not from you, and fewer of them because of caching. The domain's authoritative servers see that some resolver asked for one of their names, and some resolvers pass along a shortened form of the user's network address so the answer can suit the region.

Anyone on the path between your device and the resolver can read unencrypted queries. Encrypted DNS closes that gap, though the resolver itself still sees everything, and the address you then connect to remains visible to your network. DNS over HTTPS and DNS over TLS compares the two encrypted options.

Why one page means many lookups

A single web page rarely involves a single name. The page itself comes from one hostname, while images, fonts, scripts, video and analytics may each come from others. Every new name needs its own lookup before the browser can connect to it. Caching absorbs most of the cost for popular services, but a page that pulls from many unfamiliar domains spends noticeable time just asking for directions. Site owners can reduce that by using fewer separate hostnames, or by hinting to the browser which ones to resolve early.

Watching a lookup yourself

On macOS or Linux, trace mode performs the walk from the root and prints each referral:

dig +trace www.example.com

To time a normal query against your configured resolver, run it twice and compare the Query time line:

dig www.example.com
dig www.example.com

On Windows, clear the local cache and then resolve:

Clear-DnsClientCache
Resolve-DnsName www.example.com

A trace talks to outside servers directly, so some corporate networks block it even though ordinary lookups work. In that case, rely on queries to your own resolver and compare with a second network.

Written for 4Internet with AI writing tools and not reviewed line by line by a person. Check anything you rely on with the maker, provider or standard concerned. Report an error.

Keep reading

All 45 articles in DNS & Domain Names →

Latest news on this topic