Many domains/sites hosted on same server, CNAME alternatives to avoid writing same IP in DNS?

But I read that domainx.com -> CNAME -> myserver.com is evil

CNAMEs are not evil. However using CNAMES for a second level domain will break DNS for those domains. You cannot add MX, TXT or just about any other records at the same level as the CNAME record. From rfc1912:

A CNAME record is not allowed to coexist with any other data. In
other words, if suzy.podunk.xx is an alias for sue.podunk.xx, you
can't also have an MX record for suzy.podunk.edu, or an A record, or
even a TXT record. Especially do not try to combine CNAMEs and NS
records

Technically this might work, but mixing CNAMES with other records may confuse other DNS servers, which is going to cause to cause strange failures and will be an administrative headache.


Although CNAME for domains is evil, there exists a little known DNAME which will do pretty much exactly what you want (and it intended for just that). If will also allow to override certain entries in subdomains (e.g. spf text records, etc..., if you need to) - see this question and my answer for an example.