Autocoder

DNS Interview Questions: Resolution, Record Types, Caching and Troubleshooting

Last updated 2026-11-19

DNS is on almost every networking and DevOps interview, usually as one of the first questions: what happens when I look up a name? A good answer names the participants (stub resolver, recursive resolver, root, TLD and authoritative servers), says where caching happens and how TTL controls it, and ends with how you would debug a failure. This page gives those answers and covers record types, reverse lookups, security and the numerical on lookup time.

DNS is also step one of what happens when you type a URL, and it rides on UDP and TCP as described in TCP vs UDP interview questions. For preparation, see how to crack a computer networks interview.

PortsUDP and TCP 53 (853 for DNS over TLS, 443 for DNS over HTTPS)
LimitsLabel 63 characters, full name 253 characters
NumericalLookup time with and without caching, TTL expiry

The players in a lookup

DNS Interview Questions: questions with worked answers

  1. 1

    What is DNS and why is it needed?

    easy

    The Domain Name System is a distributed, hierarchical database that maps human-readable names such as www.example.com to IP addresses (and other data). People remember names, while routing needs addresses. DNS also lets operators change a server's IP without users noticing, spread load across several addresses and route mail with MX records. It is organised as a tree with the root at the top, then top-level domains, then domains and subdomains.

  2. 2

    Explain how a DNS lookup for www.example.com works.

    easy

    The application asks the OS stub resolver, which checks its own cache and the hosts file, then sends a recursive query to the configured resolver. If the resolver has no cached answer it asks a root server, which refers it to the .com TLD servers; the TLD servers refer it to example.com's authoritative name servers; the authoritative server returns the A or AAAA record. The resolver caches each answer for its TTL and returns the final answer to the client, which also caches it.

    bash
    dig www.example.com +trace      # shows root -> TLD -> authoritative
    dig www.example.com A +short
  3. 3

    What is the difference between recursive and iterative queries?

    medium

    In a recursive query the client asks the resolver to return the final answer or an error, and the resolver does all the work. In an iterative query the server returns the best answer it has, often a referral to another server, and the asker follows the referral itself. Stub resolvers send recursive queries to a recursive resolver, and the resolver sends iterative queries to the root, TLD and authoritative servers.

  4. 4

    Name the common DNS record types and what each is for.

    medium

    A maps a name to an IPv4 address and AAAA to IPv6. CNAME makes a name an alias of another name. MX gives mail servers for a domain with a preference value (lower is tried first). NS lists the authoritative name servers of a zone. TXT holds free text, used for SPF, DKIM and domain verification. PTR maps an address back to a name for reverse lookups. SOA holds zone metadata such as the serial number and refresh timers. SRV gives host and port for a service, and CAA restricts which certificate authorities may issue certificates.

  5. 5

    What is the difference between an authoritative server and a recursive resolver?

    medium

    An authoritative server holds the original records of a zone and gives definitive answers about it, but does not look up names outside its zones. A recursive resolver holds no zones; it fetches answers from authoritative servers on behalf of clients and caches them. Public resolvers such as those run by ISPs and large providers are recursive, while the name servers at your DNS host or registrar are authoritative.

  6. 6

    How does DNS caching and TTL work, and what should you do before a migration?

    medium

    Every record has a time to live in seconds. Resolvers and clients may reuse a cached record until the TTL expires, which reduces load and latency, and means a changed record spreads gradually. Before moving a site to a new IP, lower the TTL (for example from 86400 to 300 seconds) at least one old-TTL period in advance, make the change, and raise the TTL again afterwards. Negative answers such as NXDOMAIN are cached too, for a period set by the SOA record.

  7. 7

    Numerical: The RTTs from a resolver are: root 50 ms, TLD 40 ms, authoritative 30 ms, and the client to resolver RTT is 10 ms. Estimate the lookup time with a cold cache, then with the NS records cached, then with the answer cached.

    medium

    Cold cache: client to resolver 10 ms, then the resolver makes three sequential queries: 50 + 40 + 30 = 120, so 130 ms in total. If the resolver already cached the NS records for example.com it skips the root and TLD, so 10 + 30 = 40 ms. If it cached the final answer it replies at once: 10 ms. If the client itself has the answer in its OS cache the time is near zero. This is why long TTLs improve latency.

  8. 8

    Numerical: A record has a TTL of 300 seconds and was cached by a resolver at t = 0. A client asks at t = 200 s and again at t = 350 s. What happens at each query?

    medium

    At t = 200 s, 100 s of TTL remain, so the resolver answers from cache and returns the record with a remaining TTL of 100. At t = 350 s the entry expired at t = 300, so the resolver queries the authoritative server again, gets the current value, and caches it with a fresh 300 s. If the address changed at t = 100, the client would still see the old address at t = 200 and the new one at t = 350.

  9. 9

    What is a reverse DNS lookup?

    medium

    A reverse lookup finds the name for an IP address using PTR records under the special domain in-addr.arpa (ip6.arpa for IPv6), with the octets written in reverse order. The address 192.0.2.10 is queried as 10.2.0.192.in-addr.arpa. It is used for logging, anti-spam checks (mail servers often expect the sending IP to have a matching PTR) and troubleshooting. dig -x 192.0.2.10 performs it.

  10. 10

    Why can't a CNAME be used at the zone apex, and what are the alternatives?

    medium

    A CNAME says this name is an alias for another name and cannot coexist with any other record at the same name. The apex (example.com) must carry SOA and NS records, so a CNAME there would conflict. DNS providers solve this with ALIAS or ANAME records, or CNAME flattening, which resolves the target on the server side and returns A records. Alternatively point the apex at fixed A records and use CNAME only for subdomains such as www.

  11. 11

    How does DNS provide load balancing and failover?

    medium

    A name can have several A records, and resolvers rotate their order (round-robin), spreading clients. Geographic or latency-based DNS returns different addresses depending on the client's location. Health-checked DNS removes a failed server's record, though clients may keep it until the TTL expires, so short TTLs are used. DNS balancing is coarse because caching defeats fine control, which is why load balancers and anycast are used for finer or faster failover.

  12. 12

    A website works by IP address but not by name. How do you troubleshoot?

    medium

    Confirm with dig or nslookup that the name fails to resolve and see which server answered. Compare results from another resolver (dig @8.8.8.8 example.com) to separate a local resolver problem from a record problem. Check /etc/resolv.conf and the hosts file, flush the local cache (resolvectl flush-caches on systemd-resolved), check that the authoritative servers respond with dig NS and dig @ns1... , and verify the record has not expired, been misspelled or missing at the registrar's delegation.

    bash
    dig example.com            # status: NOERROR, NXDOMAIN or SERVFAIL
    dig @8.8.8.8 example.com   # ask a different resolver
    dig example.com NS +short  # find authoritative servers
    dig @ns1.example.net example.com
  13. 13

    What do the DNS response codes NXDOMAIN and SERVFAIL mean?

    medium

    NXDOMAIN means the name does not exist, and the answer is authoritative and cacheable. SERVFAIL means the resolver could not obtain an answer, for example because the authoritative servers did not respond, returned errors, or DNSSEC validation failed. REFUSED means the server will not answer that client. NOERROR with an empty answer means the name exists but has no record of that type.

  14. 14

    What attacks target DNS, and how does DNSSEC help?

    hard

    In cache poisoning an attacker tricks a resolver into storing a forged answer, redirecting users to a malicious address; randomised source ports and query IDs make guessing hard. DNS amplification abuses open resolvers for DDoS reflection, and DNS tunnelling hides data in queries. DNSSEC signs records with digital signatures chained from the root, so a validating resolver can detect forged data, but it does not encrypt queries. DNS over TLS and DNS over HTTPS encrypt the path between client and resolver. See network security interview questions.

  15. 15

    How do the 13 root server addresses actually work?

    hard

    There are 13 root server identities, named A through M, so that the list fits in a single UDP response, but each is served by many machines worldwide using anycast, so the same IP is announced from hundreds of locations and queries go to the nearest. Resolvers ship with a hints file containing the root addresses, and they cache TLD referrals for a long time, so root servers see relatively few queries.

  16. 16

    What are glue records?

    hard

    If a domain's name servers are inside the domain itself, for example ns1.example.com serving example.com, a resolver cannot look up ns1's address without first resolving example.com, which is circular. Glue records are A or AAAA records for those name servers stored in the parent (TLD) zone and sent along with the referral, breaking the loop.

Frequently asked questions

What port does DNS use?

Port 53, over UDP for normal queries and over TCP for large responses and zone transfers. DNS over TLS uses 853 and DNS over HTTPS uses 443.

What is the difference between an A record and a CNAME?

An A record maps a name directly to an IPv4 address. A CNAME maps a name to another name, which is then resolved further, so changing the target's address changes every alias at once.

What is the hosts file?

A local text file (/etc/hosts on Linux and macOS) mapping names to IP addresses that is checked before DNS on most systems, handy for testing or blocking a name.

How long does DNS propagation take?

There is no central propagation. A change becomes visible as each resolver's cached copy expires, so it takes up to the old TTL, plus delays for any NS or registrar changes.

Related guides

More in CS Fundamentals Interview Questions

See all in this section