CNAME and A record have different TTLs. Which one will be cached?
Solution 1:
The CNAME should cache for an hour (the alias value), but when the corresponding A is looked up, it will only cache for a total of 1 minute. You're talking about two independent records that are handled separately.
Solution 2:
Using Google's public DNS servers, the expiration of the A record causes a query of the CNAME record as well, even if the CNAME has a longer TTL.
We painfully experienced that because the DNS provider charged us for DNS queries. The CNAME hosted by the DNS provider had a TTL of several days. The TTL of the A record was hosted on Windows Azure with a TTL of 10 seconds. The DNS provider charged us for 7.5 million queries.
Solution 3:
You can see that the CNAME and subsequent record have different TTLs by using dig..
dig docs.nwesd.org
; <<>> DiG 9.5.1-P3 <<>> docs.nwesd.org
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 28244
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 4, ADDITIONAL: 4
;; QUESTION SECTION:
;docs.nwesd.org. IN A
;; ANSWER SECTION:
docs.nwesd.org. 7200 IN CNAME ghs.google.com.
ghs.google.com. 16662 IN CNAME ghs.l.google.com.
ghs.l.google.com. 195 IN A 74.125.95.121
;; AUTHORITY SECTION:
google.com. 32196 IN NS ns1.google.com.
google.com. 32196 IN NS ns4.google.com.
google.com. 32196 IN NS ns3.google.com.
google.com. 32196 IN NS ns2.google.com.
;; ADDITIONAL SECTION:
ns1.google.com. 32193 IN A 216.239.32.10
ns2.google.com. 32193 IN A 216.239.34.10
ns3.google.com. 70187 IN A 216.239.36.10
ns4.google.com. 242861 IN A 216.239.38.10
;; Query time: 102 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Wed Mar 17 18:40:05 2010
;; MSG SIZE rcvd: 232
To show that you get both the CNAME and the what it is pointed at is returned in a single request to a recursive server.
18:40:05.418435 IP 192.168.32.10.24712 > 216.146.36.113.53: UDP, length 43
0x0000: 4500 0047 4e58 0000 4011 4e98 c0a8 200a [email protected].....
0x0010: d892 2471 6088 0035 0033 aae5 f66c 0100 ..$q`..5.3...l..
0x0020: 0001 0000 0000 0001 0464 6f63 7305 6e77 .........docs.nw
0x0030: 6573 6403 6f72 6700 0001 0001 0000 2910 esd.org.......).
0x0040: 0000 0080 0000 00 .......
18:40:05.519081 IP 216.146.36.113.53 > 192.168.32.10.24712: UDP, length 243
0x0000: 4500 010f b93a 0000 3511 eded d892 2471 E....:..5.....$q
0x0010: c0a8 200a 0035 6088 00fb 6ceb f66c 8180 .....5`...l..l..
0x0020: 0001 0003 0004 0005 0464 6f63 7305 6e77 .........docs.nw
0x0030: 6573 6403 6f72 6700 0001 0001 c00c 0005 esd.org.........
0x0040: 0001 0000 1c20 0010 0367 6873 0667 6f6f .........ghs.goo
0x0050: 676c 6503 636f 6d00 c02c 0005 0001 0000 gle.com..,......
0x0060: 4116 0008 0367 6873 016c c030 c048 0001 A....ghs.l.0.H..
0x0070: 0001 0000 00c3 0004 4a7d 5f79 c030 0002 ........J}_y.0..
0x0080: 0001 0001 11ac 0006 036e 7333 c030 c030 .........ns3.0.0
0x0090: 0002 0001 0001 11ac 0006 036e 7332 c030 ...........ns2.0
0x00a0: c030 0002 0001 0001 11ac 0006 036e 7334 .0...........ns4
0x00b0: c030 c030 0002 0001 0001 11ac 0006 036e .0.0...........n
0x00c0: 7331 c030 c0a2 0001 0001 0000 7dc1 0004 s1.0........}...
0x00d0: d8ef 200a c07e 0001 0001 0000 7dc1 0004 .....~......}...
0x00e0: d8ef 220a c06c 0001 0001 0002 0204 0004 .."..l..........
0x00f0: d8ef 240a c090 0001 0001 0003 b4ad 0004 ..$.............
0x0100: d8ef 260a 0000 2910 0000 0080 0000 00 ..&...)........