I have many sites (each one with its own domain) all on the same cPanel hosted server (let's say server IP is 1.1.1.1
and server main domain is myserver.com
)
All these domains use third party DNS (not the cPanel hosted ones), I set up the DNS of each one of these domain to point to server IP. Example of how each domain DNS is currently set:
domainx.com -> A -> 1.1.1.1
domainx.com -> MX -> mail.domainx.com
mail.domainx.com -> A -> 1.1.1.1
www.domainx.com -> CNAME -> domainx.com
ftp.domainx.com -> CNAME -> domainx.com
This situation obliges me to repeat hundreds times the server IP 1.1.1.1
one time for each domain. In the event that server IP changes I will have to go through each domain DNS to update records with new IP.
So I thought why not use CNAME to avoid rewriting server IP everywhere?! I could set each domain DNS like the following:
domainx.com -> CNAME -> myserver.com
domainx.com -> MX -> mail.myserver.com
mail.domainx.com -> CNAME -> myserver.com
www.domainx.com -> CNAME -> myserver.com
ftp.domainx.com -> CNAME -> myserver.com
But I read that domainx.com -> CNAME -> myserver.com
is evil, see this and this.
But what alternatives do I have to avoid rewriting server IP everywhere?
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:
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.
Why not use a single zone file in BIND?
You make a zone file called
virtual_hosts
, and place the A records, MX records, etc in there. Then in thenamed.conf
file you point each "simple" domain to the same zone file.If you have a lot of zones and/or records, you might be better off using APIs to implement them rather than handling them all manually through web interfaces.
Most reputable DNS providers have APIs available. (Example, example, Wiki page.)
use wildcard (*) for records pointing the same IP
Such that test.com is your domain:
In that case every sub domain will have the A record 1.1.1.1 including www