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.

Lets say I have a webserver, called 'www'. www.example.com resolves to the IP address of that machine. Then I wanna make some virtual hosts, and DNS records for them, like webmail.example.com.

For 'webmail', should I put in an A record with www's IP address, or should I do a CNAME to www?

What's 'cleaner?, more robust? better?

share|improve this question

5 Answers 5

up vote 23 down vote accepted

There are two alternate views of this question, and it's one that is ultimately going to be debated forever. I'm not going to give my opinion (because I'm torn myself), but the general arguments each way typically are:

  • You should define A records for your physical machines, and then CNAME services onto those machines. This does make it rather clear as to what is what, and in the event that you need to renumber there's not a lot of records to change -- just the machine records. On the other hand, it does increase your DNS lookup load somewhat, and "auxiliary" IPs (think SSL vhosts) don't fit neatly into this model.

  • The literal meaning of "canonical name" (CNAME) is to define strict aliases of the same name (think mail and smtp), and if you have multiple services running on the same machine they should all have A records, because it reduces load on DNS and some services (NS records and, to a lesser extent, MX records) really aren't impressed with dealing with CNAMEs, so if you have to handle those services differently anyway, we may as well do it for everything.

share|improve this answer
12  
You can actually seriously ruin/overload your DNS server by pointing an MX to a CNAME. I can't be bothered explaining why right now but older mail servers (there are plenty of them out there) will see an MX pointing to a CNAME and won't know how to deal with it and will keep looking up and put huge stress on your DNS and in the end the email never gets anywhere. DONT POINT MX TO A CNAME. EVER. –  Mark Henderson Aug 20 '09 at 10:20
3  
I agree with Farseeker, don't point MX to a CNAME even if it may work. Have a look to wikipedia (search for MX Record) or RFC 2181 (section 10.3) if you want the full details. –  Benoit Aug 20 '09 at 11:19
    
+1 to womble. That answer expresses my view also. +1 to Farseeker. MX records are the exception. As for Beoot's references, Wikipedia should never be used as a technical reference, as there are far too many errors and inaccuracies. While almost everyone likes to quote RFCs we do need to remember they are not standards, merely a precursor to a proposal for a standard. –  John Gardeniers Aug 20 '09 at 12:12
    
Sorry for the mis-spelling of Benoit's name. It's time I was in bed. –  John Gardeniers Aug 20 '09 at 12:13
    
I always used cnames. My colleague took the approach of multiple a records. One more reason cname is better: it makes it easy to decide which a record gets the ptr record. I earned a beer from a third colleague on this one. –  dmourati Jun 6 '13 at 1:45

Using a CNAME effectively doubles the lookups on the DNS server. When a request maps to a CNAME, it needs to then look up the A record for the CNAME.

That said, there's a reason CNAME's exist. It makes your DNS so much easier to manage, and unless you're doing tens of thousands of resolutions a day it's not going to matter...

share|improve this answer

Several relies here suggest that CNAMEs increase DNS load. This made me curious. I fired up wireshark, inspected a request for a CNAME, and at least in our environment the result was returned in one record. Which brings Knuth's aphorism to mind here: "premature optimization is the root of all evil".

I like CNAMEs, but mostly for their psychological effect. They encourage people (like me for instance) to uncouple server names from service names.

Our environment has several SSL certs attached to opaque server names (which we've quit doing). CNAMEs work much better here. In every place I've worked migrating services where the server name is tightly coupled to the service is a headache. CNAMEs give clear conceptual line of separation.

share|improve this answer
    
This needs more upvotes. CNAME records typically don't increase the number of round-trips required, as the results are bundled into a single response. –  Nic Jun 15 '13 at 3:36

In my opinion, if the virtual hosts are www.someotherdomain.com, then I would treat them as a separate domain with there own set of DNS records (makes it easier later on if they need to be split out). If however its just blog.example.com, then I would use a CNAME.

Just my personal preference.

share|improve this answer

I would use CNAME because of the perspective of DNS, webmail is an alias to www.

share|improve this answer

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.