Do CNAME records result in a second DNS lookup

domain-name-system

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.

Best Answer

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.

Related Topic