Setting up DNS records for a shared host

best practicesdomain-name-systemsmtp

So I'm setting up this server right now that'll host multiple websites / domains. What are the current best practices with regard to DNS records? I admit to 'just having done something' up to now, which is pretty bad. Mea culpa. And though it has worked for me in the past, I'd like to know what the best way of doing things is, so here's a couple of questions about it:

  1. I think it probably makes the most sense to setup the main hostname like this

    192.168.0.1   A      example.com
    192.168.0.1   A      host.example.com
    www           CNAME  example.com
    

    and then a single PTR record for 192.168.0.1 back to example.com. Should the www CNAME point to the example.com or to the host.example.com A records? What makes more sense and why?

  2. Would it then make the most sense to create a CNAME for each Virtualhost on this server to the example.com A record (or the host.example.com A record), or to create individual A records for each Virtualhost to the main IP address?

  3. The SMTP server on this host will identify itself as host.example.com. Is SPF uptake broad enough already that I can create an SPF record for each hosted domain and have that take care of other domains possibly rejecting mail from this host?

Best Answer

Addressing 1 and 2: In most cases, I would recommend doing a single "A" record for the actual IP associated with the box and CNAME everything you need to that. If you are going to have a lot of somethings.example.com, I would make use of a wildcard entry

example.com     A      192.168.0.1
*.example.com   CNAME  example.com

The benefit being that you don't have to do a lot of DNS maintenance as whatever .example.com you use will already match. You just let apache figure out what to do with it based on the name given. This would result in 2 look-ups, and I would only do many CNAMEs to one A, and not try doing CNAME->CNAME. Additionally MX records must only point to an A record name.

If you ever need to break a vhost off to its own IP addres, you can then just add an "A" record for that one host and the most-specific answer will win.

example.com     A      192.168.0.1
*.example.com   CNAME  example.com
new.example.com A      192.168.0.2