How are intermediate stages of an iterative DNS query cached?
19:35 31 May 2026

So I'm writing a custom DNS resolution implementation for an internet research tool, and I need to know the specifics of DNS caching while doing an iterative lookup.

For example, let's take a hypothetical DNS resolution of www.example.org with a CNAME alias dyna.examples.org:

  1. Query a root server for www.example.org

  2. Get the IP address of the .org TLD nameserver, with a TTL of 48 hours

  3. Query the .org nameserver

  4. Get the IP address of example.org authoritative nameserver, with a TTL of 1 hour

  5. Query the example.org nameserver

  6. Get the CNAME alias for www.example.org, which is dyna.examples.org, with a TTL of 24 hours

  7. Requery root server for dyna.examples.org

  8. Get the IP address of the .org TLD nameserver, with a TTL for 48 hours

  9. Query the .org nameserver

  10. Get the IP address of examples.org authoritative nameserver, with a TTL of 1 hour

  11. Query the examples.org nameserver

  12. Get the final IP address for the DNS lookup, with a TTL of 3 minutes.

So there's the obvious redundant requery of the root server, when we should clearly just query the .org TLD nameserver, but that's all within a single lookup so that's obvious enough. My question is if a user is trying to access www.example.org either >3 minutes, then >1 hour, then >24 hours later, and so on, which parts of our query do we reuse?

My guess would be that when a user tries to access www.example.org:

  • after 3 minutes: repeat step 11

  • after 1 hour: repeat step 9. We don't repeat step 3 because our CNAME alias answer is still valid.

  • after 24 hours: repeat step 3, as step 6 and step 4 have expired.

  • after 48 hours: repeat step 1

Are there any cases during DNS resolution that I would want to discard a resource record even if its TTL has not yet expired?

network-programming dns