Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Let's say we have a subdomain called www.foo.com which has a CNAME record pointing at foo.bar.cc. Foo.bar.cc in turn has an A record pointing at the IP address 1.2.3.4.

Now, if I do a DNS lookup of www.foo.com I'll get an answer looking like this:

www.foo.com. IN CNAME foo.bar.cc.
foo.bar.cc. IN A 1.2.3.4

My question is, at what stage is foo.bar.cc resolved? Is it done by the recursive DNS server before the response is sent back to the client? Or does the client issue a second request to the DNS server, this time for foo.bar.cc? Or does it depend on whether the DNS server already has a cached entry for foo.bar.cc?

I'm asking because one particular recursive DNS server returns only the first line, ie it does not resolve the CNAME. However, after perhaps 20 seconds, subsequent requests for the same host will then include both lines.

share|improve this question
add comment

1 Answer

up vote 11 down vote accepted

The 2 records are returned together in the same request. You can find that out via the following command

dig +trace www.foo.com

For example my domain photoblog.com has a cname for www so the last 2 requests from photoblog's name server to me look like

photoblog.com.      172800  IN  NS  ns1.photoblog.com.
photoblog.com.      172800  IN  NS  ns2.photoblog.com.
;; Received 103 bytes from 192.43.172.30#53(i.gtld-servers.net) in 196 ms

www.photoblog.com.  600 IN  CNAME   photoblog.com.
photoblog.com.      600 IN  A   74.52.128.18
photoblog.com.      60  IN  NS  ns2.photoblog.com.
photoblog.com.      60  IN  NS  ns1.photoblog.com.
;; Received 133 bytes from 74.52.128.18#53(ns2.photoblog.com) in 59 ms

As you can see the request asks ns1/ns2 what is the ip for www.photoblog.com and it returns well it's a cname to photoblog.com and here is the ip for that A record.

share|improve this answer
    
In the OPs your example where it gave just the CNAME back, the DNS server likely had difficulty following the CNAME and so gave the client whatever information it had. Eventually, it finished following the CNAME and so was able to give a complete reply. –  David Schwartz Aug 21 '12 at 14:10
    
Yeah - if the DNS server has more information, then it will return it in the ADDITIONAL section of the answer. The occasions where it doesn't return it mean that the recurser didn't have it in its cache - potentially because the CNAME and the A record it points to have different authoritative servers (so the recurser's initial request didn't get the CNAME plus additional A response, just the CNAME). –  Shane Madden Aug 22 '12 at 4:10
    
@Mike: so what's the conclusion? Does the CNAME records result in a second DNS lookup or not? If not, why many suggests to increase CNAME record TTL? –  Marco Demaio Feb 22 '13 at 13:32
1  
as long as the A record is in the same authoritative server as the CNAME it's the same lookup –  Mike Feb 22 '13 at 19:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.