Does a client cache the IP of a CNAME DNS request or the other domain

cname-recorddomain-name-system

I am contemplating using two different DNS hosts and am curious as to how a client system would cache the CNAME record. The reason I am going this route is that a primary domain that I would like to use is already hosted in one DNS service but the application is hosted in another service that has its own DNS handling that is integrated with the services.

Specifically what I am looking to understand is, if friendly.abc.com is a CNAME record that points to long-ugly-url.hosted-service.com which is itself hosted (DNS and application) on another service with an IP of 1.2.3.4, will the clients accessing friendly.abc.com be caching long-ugly-url.hosted-service.com or 1.2.3.4? The reason I ask is that if it is the former, then the long-ugly-url.hosted-service.com A record can have a short TTL and it can be changed quickly while the friendly.abc.com can be set at a higher TTL but still have changes "propagated" quickly. If it is the latter, then both would need to have short TTLs for responsible clients to see the changes quickly.

Best Answer

I would say both. Implementations might vary but considering that the whole point of caching is not to fetch something which you have already done so a moment ago, it seems illogical for a client to get a CNAME and A record and throw away one or the other. I am using the term 'client' vaguely here as you have it in your question, but the implementation could vary whether we are talking about a dns resolver (such as dig, nslookup), application dns caching (such as browsers), dns caching server( eg. BIND) etc. If you want to be certain, you have either to rely on the documentation of the particular client or do your own testing.

In my case I tested it on BIND9. The simple testing technique I used is, first I flushed all the dns entries in the cache and then made a DNS query, finally dumped the dns cache for investigation. As you can see below, both the CNAME and A records were cached. The TTL does not match the actual TTL stored on the authoritative zone file because I am getting my DNS through forwarding, which means the dns entries I am getting could be coming from the remote DNS servers cache as well.


ns1 bind # rndc flush && dig www.bbc.co.uk +nodnssec && rndc dumpdb
;; ANSWER SECTION:
www.bbc.co.uk.      238 IN  CNAME   www.bbc.net.uk.
www.bbc.net.uk.     166 IN  A   212.58.246.55
www.bbc.net.uk.     166 IN  A   212.58.246.54

ns1 bind # grep www.bbc.co.uk named_dump.db 
www.bbc.co.uk.      234 CNAME   www.bbc.net.uk.
ns1 bind # grep  -P 212.58.246.5[4,5] named_dump.db
www.bbc.net.uk.     166 A   212.58.246.54
            166 A   212.58.246.55