skip to content

DNS

How a name becomes an address: record types, the resolver chain, TTL caching and delegated zones, over plain or encrypted transports. It sits behind every 'what happens when you type a URL' question.

on this pageshow

questions

page 1 of 2

In DNS, what does a record's TTL control, and why can clients keep getting the old address after you change the record?

level: juniorimportance: must knowfreq 68%

answer

  1. set by the zone's owner
  2. seconds, not hops
  3. every cache counts down
  4. old copies live until expiry

basics

~20 s

A DNS TTL is the number of seconds a cache may keep a record before consulting the authoritative source again. Resolvers that cached the old record can keep serving it until their copy's remaining TTL runs out.

solid answer

~50 s

The TTL is a 32-bit field on every DNS resource record, set by the zone's administrator, giving the number of seconds a resolver may cache that record before it must ask the source again (RFC 1035 §3.2.1; RFC 2181 §8 limits the value to 0 through 2^31-1). Changing the record on the authoritative server pushes nothing out: every recursive resolver that already fetched the old answer may keep serving it until its copy expires, so the change appears gradually over up to one old TTL. A cache hands out the *remaining* TTL, counted down since it fetched the record, so a chain of conforming caches does not stretch that window. A TTL of `0` means use the record for the current transaction only. It is a cache lifetime in seconds and has nothing to do with the IP header's TTL, which counts router hops.

go deeper

for a junior

Recall that a TTL is the number of seconds a cache may keep a record, set by the zone owner, and that already cached copies survive until they expire.

for a middle

Explain the countdown: each cache hands on the remaining TTL, so the spread of a change is bounded by the old TTL rather than multiplied by the number of caches.

for a senior

Show that the TTL is a ceiling rather than a floor (RFC 2181 §8), that holders outside the resolver can ignore it, and that change plans start from the old value.

for a principal

Treat the TTL as a lever between change agility and query load or resilience, and set it per record according to how often that record must move.

## What the TTL field is Every DNS **resource record** (an A record holding an IPv4 address, an AAAA record holding an IPv6 address, an MX record naming a mail server, and so on) carries a **TTL** (time to live). RFC 1035 §3.2.1 defines it as the time interval, in seconds, that the record **may be cached before the source of the information should again be consulted**. - The value is chosen by whoever administers the **zone** the record lives in, not by the resolver that caches it. - RFC 1035 described the field inconsistently (signed in one place, unsigned in another); **RFC 2181 §8** fixed it as an unsigned number from `0` to `2147483647` (2^31-1). - RFC 2181 §8 also says the TTL is a **maximum time to live, not a mandatory one**: a cache may throw a record away earlier, and may cap very large values. - **RFC 8767** later recommended that resolvers cap TTLs at `604800` seconds (7 days). - All records of one type at one name (an **RRset**) must share the same TTL (RFC 2181 §5.2). - A TTL of `0` means the record can be used only for the transaction in progress and should not be cached. ## Who counts it down A DNS answer usually passes through more than one cache before an application uses it. The authoritative server holds the zone itself; a **recursive resolver** fetches and caches answers for many clients; a forwarding resolver or a cache on the client side may sit in front of it. | Holder | What it keeps | TTL it hands on | |---|---|---| | Authoritative server | The zone data | The full TTL written in the zone | | Recursive resolver | A copy fetched at some moment | The **remaining** TTL: original minus time already cached | | Downstream cache | A copy of the resolver's copy | Whatever is left of the remaining TTL | Because each conforming cache passes on only what is left, the copy's expiry time stays fixed as it moves downstream: a chain of caches does **not** add their delays together. RFC 1034 shows the telltale sign of a cached answer: the **AA** (authoritative answer) bit is not set and the TTL is lower than the zone's value, the difference being the time the data has aged in the cache. ## Why a change is not live everywhere at once Editing the record on the authoritative server is not a push. Nothing tells the caches that already hold the old answer. Consider a record with TTL `3600` changed at 10:00: 1. Resolver A fetched the old record at 09:00. Its copy expires at 10:00, so it fetches the new answer on its next lookup. 2. Resolver B fetched the old record at 09:50. Its copy is valid until 10:50, and it serves the old address for the rest of that hour. 3. Resolver C had never looked the name up. Its first lookup after 10:00 gets the new answer immediately. The result is a gradual rollover lasting up to **one old TTL**. "DNS propagation" is really this: independent caches expiring at different moments. Flushing the cache on your own machine only fixes your own view; other resolvers' copies are outside your control. Two consequences follow: - The TTL that governs how fast a change spreads is the **old** one, the value that caches received when they last fetched the record. A lower TTL published now only reaches a cache when its current copy expires. - Some holders go beyond what the resolver does: an application or long-running process may keep its own copy of an answer, or reuse an open connection, regardless of the TTL. The DNS specification bounds the resolver caches, not those. ## Two TTLs that are not the same The word **TTL** appears in two unrelated places: - The **DNS TTL** is a cache lifetime in **seconds**, carried inside each resource record. - The **IP TTL** (the hop limit in IPv6) is a field in the IP header, decremented by each router, that stops a packet looping forever. It counts **hops** and has nothing to do with how long a DNS answer is cached. Confusing the two is a common interview slip: a DNS reply crossing twelve routers does not change the record's TTL at all. ## What to take away A TTL is a promise the zone owner makes to every cache: this answer stays usable for this many seconds. It trades freshness against load: a long TTL means fewer queries and faster lookups but slower changes, a short TTL means faster changes but more queries to the authoritative servers. When someone asks why a DNS change "has not propagated", the answer is almost always that caches are still inside the old TTL.

  • If a DNS record has a TTL of 0, is every lookup guaranteed to reach the authoritative server?
    No. RFC 1035 says a zero TTL means the record should not be cached and is usable only for the transaction in progress, and conforming resolvers follow that. But it is a 'should', and caches outside the resolver, such as an application holding its own copy, are not bound by it. It also multiplies query load and adds a full lookup to every request.
  • How can you tell from a DNS response whether it came from a cache rather than the authoritative server?
    A cached answer does not have the `AA` (authoritative answer) bit set, and its TTL is lower than the value in the zone because the resolver hands out the remaining lifetime of its copy. RFC 1034 uses exactly that difference to show an answer that was served from a cache.

A DNS TTL works like a printed timetable stamped 'valid until' a date: people who picked up a copy keep using it until that date even if the master timetable changes, and a photocopy made later carries the same expiry date, not a fresh one.

saying these in an interview costs you the question

  • The DNS TTL is the number of routers a DNS packet may cross.
  • Changing the record on the authoritative server pushes the update to resolvers.
  • Each cache in a chain restarts the full TTL, so delays add up per hop.
  • Flushing my own machine's DNS cache makes the change live for everyone.
  • A lower TTL published now shortens copies that are already cached.
open as a page

Does DNS use UDP or TCP, and when does a DNS query move from UDP port 53 to TCP?

level: juniorimportance: must knowfreq 62%

basics

~20 s

DNS uses both. Queries normally travel over UDP port 53; a response too large for UDP (512 bytes without EDNS0) comes back with the TC bit set, and the client repeats the query over TCP port 53, which RFC 7766 makes mandatory.

open as a page

Which DNS record types does example.com need to serve a web app and receive email, and what does each one answer?

level: juniorimportance: must knowfreq 74%

basics

~20 s

A and AAAA map a name to IPv4 and IPv6 addresses, CNAME makes one name an alias of another, MX names the mail servers with a preference (lower first), and TXT carries free-form strings such as verification tokens.

open as a page

With every DNS cache empty, which servers take part in resolving www.example.com, and in what order is each one asked?

level: juniorimportance: must knowfreq 78%

basics

~20 s

The stub resolver asks a recursive resolver; that resolver asks a root server, then a com server, then example.com's authoritative server. The first two refer it onward, the last answers, and the recursive resolver returns the address to the stub.

open as a page

What is DNS cache poisoning, and why does one forged answer accepted by a recursive resolver affect many users?

level: juniorimportance: must knowfreq 52%

basics

~20 s

DNS cache poisoning is getting a recursive resolver to accept and store a forged answer. Because the resolver serves its cache to every client, one accepted forgery misdirects all of them until the record's TTL runs out.

open as a page

When a DNS name returns several A records, how does round-robin DNS spread clients across the addresses, and why is it a coarse load balancer?

level: juniorimportance: must knowfreq 62%

basics

~20 s

Round-robin DNS publishes several A or AAAA records for one name, and the server typically rotates their order, so clients taking the first address spread out. It is coarse: DNS sees no load or health, and cached answers are shared.

open as a page

In DNS, what is the difference between a domain and a zone, and what makes a name server authoritative for a zone?

level: juniorimportance: must knowfreq 52%

basics

~20 s

A DNS domain is a whole subtree of names; a zone is the connected part of it that one set of servers answers for, from its apex down to any delegation. The apex SOA and NS records define the zone.

open as a page

What do the DNS response codes NOERROR, NXDOMAIN, SERVFAIL and REFUSED mean, and how does a NODATA answer differ from NXDOMAIN?

level: middleimportance: must knowfreq 48%

basics

~20 s

NOERROR (0) is success, NXDOMAIN (3) says the name does not exist, SERVFAIL (2) that the server could not answer, REFUSED (5) a policy refusal. NODATA is not an rcode: NOERROR with an empty answer, so the name exists without that type.

open as a page

Why can't a DNS CNAME record be placed at the zone apex example.com, and what can you do instead?

level: middleimportance: must knowfreq 52%

basics

~20 s

A CNAME may not share its name with other data (RFC 2181 §10.1), yet the apex must hold the zone's SOA and NS records, so a CNAME there is illegal. Publish A/AAAA at the apex or use a provider's flattening feature.

open as a page

In DNS, what is the difference between a recursive and an iterative query, and which party in a normal lookup sends each kind?

level: middleimportance: must knowfreq 64%

basics

~20 s

A recursive query (RD set) asks for the final answer or an error, never a referral; an iterative one accepts referrals. Stubs send recursive queries to a recursive resolver, which iterates with non-recursive queries to root, TLD and authoritative servers.

open as a page

When a client switches from plain DNS to DoH or DoT, what does encryption protect, and who still sees the names it looks up?

level: middleimportance: must knowfreq 40%

basics

~20 s

DoT and DoH encrypt only the hop between a client and its recursive resolver, hiding names from the local network. The resolver still sees every name, authoritative servers see its onward queries, and nothing proves the answers are genuine.

open as a page

In DNS, how do you delegate the subdomain dev.example.com to another team's name servers, and what must each zone publish?

level: middleimportance: must knowfreq 45%

basics

~20 s

The other team serves a dev.example.com zone with its own SOA and apex NS records; then the example.com zone adds an NS RRset for dev.example.com naming the same servers, plus glue only for servers named inside dev.example.com.

open as a page

You must move www.example.com, whose DNS A record has a TTL of 86400, to a new server with minimal stale traffic; how do you schedule the TTL changes?

level: seniorimportance: must knowfreq 52%

basics

~20 s

Lower the TTL (say to 300) at least one old TTL, 86400 seconds, before the switch, so every long-lived copy expires first. Then change the address, keep the old server answering briefly, and raise the TTL back once stable.

open as a page

A DNS name was queried before its record existed, and resolvers keep returning NXDOMAIN after you create it; what sets how long?

level: middleimportance: should knowfreq 38%

basics

~20 s

Negative caching (RFC 2308): the NXDOMAIN reply carries the zone's SOA record, whose TTL is the smaller of the SOA's own TTL and its MINIMUM field. Resolvers keep answering NXDOMAIN until that negative TTL expires.

open as a page

Reading a DNS response header, what do the ID field and the QR, AA, RD and RA flags tell you about who answered and how?

level: middleimportance: should knowfreq 30%

basics

~20 s

The 16-bit ID pairs the reply with its query; QR=1 marks a response; AA=1 means the server is authoritative for the queried name; RD echoes whether recursion was requested; RA says whether the server offers recursion at all.

open as a page

How does DNS MX preference decide which mail server a sender tries, and what rules apply to the name an MX record points at?

level: middleimportance: should knowfreq 38%

basics

~20 s

Each MX record holds a 16-bit preference and an exchange host name; senders try the lowest value first, pick randomly among equal values, and the exchange must be a name with its own address records, never a CNAME or an IP address.

open as a page

How does publishing a DNS TXT record prove to a third-party service that you control a domain, and what makes that proof weak or slow?

level: middleimportance: should knowfreq 34%

basics

~20 s

The service issues a random token and checks that the domain serves it in a TXT record, which only an editor of the authoritative zone could publish. It proves control only when checked, and a cached earlier miss can delay it.

open as a page

When a recursive DNS resolver looking up www.example.com receives a CNAME pointing into another zone, how does it assemble the final answer?

level: middleimportance: should knowfreq 32%

basics

~20 s

The resolver caches the CNAME, switches the name it is resolving to the CNAME's target and restarts there, walking to the target zone's servers if needed. The stub then gets one answer section: the CNAME record followed by the target's records.

open as a page

When a stub resolver is switched from the corporate resolver to a public anycast one such as 8.8.8.8, what changes in who resolves its lookups?

level: middleimportance: should knowfreq 34%

basics

~20 s

The recursive tier moves to the operator: an anycast site picked by routing walks root, TLD and authoritative servers from a cache shared with other users. Internal and split-horizon names stop resolving, and the operator receives every query name.

open as a page

What does a DNS referral response contain, and how does a recursive resolver use it to choose the next server to query?

level: middleimportance: should knowfreq 38%

basics

~20 s

A referral leaves the question unanswered and has AA clear; it puts the child zone's NS records in the authority section and known server addresses in the additional section. The resolver caches the delegation and queries one of those servers, resolving its address first if needed.

open as a page

How do DNS over TLS, DNS over HTTPS and DNS over QUIC differ in transport, port and message framing, and why would you choose one?

level: middleimportance: should knowfreq 22%

basics

~20 s

DoT (RFC 7858) carries DNS in TLS over TCP port 853; DoH (RFC 8484) sends it as HTTPS requests; DoQ (RFC 9250) uses one QUIC stream per query on UDP port 853. They differ in visibility, latency and head-of-line blocking.

open as a page

An authoritative DNS server answers 5% of queries for api.example.com with a canary address; why does that not mean 5% of users reach the canary?

level: middleimportance: should knowfreq 34%

basics

~20 s

The 5% applies to queries reaching the authoritative server, which are recursive resolvers' cache misses. Each drawn answer is cached for its TTL and served to every client of that resolver, so exposure follows resolver populations, not users.

open as a page

In DNS, when does a delegation need glue records in the parent zone, and what goes wrong if they are missing or stale?

level: middleimportance: should knowfreq 36%

basics

~20 s

Glue is address records for a child zone's name servers, kept in the parent and returned with the referral. It is needed when a server's name lies inside the child zone, which resolvers could not otherwise reach.

open as a page

A DNS name carrying several large TXT records resolves on most networks but times out behind one firewall; how do EDNS0's advertised UDP size, IP fragmentation and TCP fallback explain it?

level: seniorimportance: should knowfreq 20%

basics

~20 s

The resolver's EDNS0 OPT record advertises a large UDP size, so the server sends the answer untruncated; above the path MTU it is fragmented, the firewall drops the fragments, and with no reply there is no TC bit to prompt a TCP retry.

open as a page

A DNS reverse lookup of your new mail server 203.0.113.25 returns a generic hosting name; why can't you fix that in example.com's zone, and who can?

level: seniorimportance: should knowfreq 24%

basics

~10 s

The PTR record lives at 25.113.0.203.in-addr.arpa, a name delegated along address allocations to whoever holds 203.0.113.0/24, normally the hosting provider. They must set the PTR, or delegate that reverse name to you.

open as a page

How did the Kaminsky technique make off-path DNS cache poisoning practical without waiting for TTLs, and what did recursive resolvers change in response?

level: seniorimportance: should knowfreq 28%

basics

~20 s

The Kaminsky technique queries random uncached names under a target zone, so each query opens a fresh race, and forged replies carry NS records capturing the whole zone. Resolvers answered with unpredictable source ports (RFC 5452) and 0x20 case randomisation.

open as a page

Why is an open recursive DNS resolver dangerous, and what server-side configuration stops a DNS server being used as a traffic amplifier?

level: seniorimportance: should knowfreq 24%

basics

~20 s

An open resolver answers anyone, so attackers send it small UDP queries forged with a victim's address and it fires large replies at the victim; it also lets outsiders trigger lookups for poisoning. Restrict recursion to your clients and rate-limit responses.

open as a page

A GeoDNS authoritative server sends users in Europe to a US region when they use a distant recursive resolver; why does that happen, and how does EDNS Client Subnet change it?

level: seniorimportance: should knowfreq 28%

basics

~20 s

GeoDNS steers by the query's source address, usually the recursive resolver's, not the user's. EDNS Client Subnet (RFC 7871) lets the resolver send a truncated client prefix and cache answers per scoped prefix, costing cache size and privacy.

open as a page

When a DNS authoritative server does health-checked failover for app.example.com, what changes in its answers when an endpoint fails, and what bounds how fast clients follow?

level: seniorimportance: should knowfreq 42%

basics

~20 s

Health-checked failover changes only what the authoritative server returns to the next queries: the failed endpoint's address is withdrawn or replaced. Clients follow after detection time plus however long resolvers, hosts and applications keep the old answer.

open as a page

After a record is changed on a DNS zone's primary server, the secondaries keep serving the old data; how do SOA serial, NOTIFY and AXFR/IXFR normally propagate a change, and what likely broke?

level: seniorimportance: should knowfreq 28%

basics

~20 s

Secondaries transfer a zone only when the primary's SOA serial is newer: NOTIFY or the REFRESH timer triggers an SOA check, then AXFR or IXFR copies the change. Usually the serial was not advanced, NOTIFY was lost, or the transfer was refused.

open as a page

showing 1–30 of 37