CNAME versus an additional A&AAAA record

301-redirecta-recordcname-recorddomain-name-systemperformance

So, let us say that we have set-up an A record and an AAAA record for @, and for www we have set-up a CNAME pointing to @.

When a new visitor visits example.com and the webserver sends a 301 permanent redirect to www.example.com, will that still require an extra DNS lookup after the CNAME, even though it already knows @'s location?

If so, why do many companies use the CNAME method over an additional A and AAAA for www?

Finally I would like to mention that I have searched through the whole internet for an answer to this question.

Best Answer

To answer your initial question, when a CNAME is used to point www.@ in a zone, the initial CNAME lookup is performed, followed by a second lookup for the A record indicated by the CNAME. If the client has not accessed this before, typically this response will be cached and any further lookups of this A record within the TTL of the record looked up will be responded to from the cache.

Many companies use CNAME records where they have multiple subdomains of their main domain pointed to the same server. As above (response by mulaz), when the server IP or location changes, only one record needs to update, rather than a few hundred (which may be the case) saving both time, and making configuration easier.

Related Topic