Reputation: 1371
Some people are saying use an A record and others a CNAME for a catch all subdomain.
Which should I use and why?
Upvotes: 78
Views: 60561
Reputation: 16957
I think question is about to understand A
& CNAME
records deeply. I have also found this confusing but after reading couple of blogs, I came up with following understanding:
The
A
andCNAME
records are the two common ways to map a host name (name hereafter) to one or more IP address. Before going ahead, it's important that you really understand the differences between these two records. I'll keep it simple.The
A
record points a name to a specific IP address. For example, if you want the nameblog.myweb.example
to point to the server186.30.11.143
you will configure:blog.myweb.example A 186.30.11.143
The
CNAME
record points a name to another name, instead of an IP address. >TheCNAME
source represents an alias for the target name and inherits its entire resolution chain.Let's take our blog as example:
blog.myweb.example CNAME my.bitbucket.example my.bitbucket.example CNAME github.map.mybitbucket.example github.map.mybitbucket.example A 186.30.11.143
We use GitHub Pages and we set
blog.myweb.example
as aCNAME
ofmy.bitbucket.example
, which in turns is itself aCNAME
ofgithub.map.mybitbucket.example
, which is anA
record pointing to186.30.11.143
. This means thatblog.myweb.example
resolves to186.30.11.143
.Conclusion:
A
record points a name to an IP address.CNAME
record can point a name to anotherCNAME
or anA
record.
Source: Differences between A & CNAME records
Upvotes: 70
Reputation: 131
A common use for CNAMEs is to map a subdomain to a host under someone else's control.
In the case of "CNAME" record if they change the IP address you don't need to change your DNS entry. With an "A" record, you would have to update it every time.
An example of this is WordPress subdomain mapping. WordPress allows you to have a blog on something like "blog.mydomain.com", but their blogs are cloud hosted and may dynamically change IP address due to server maintenance, failover, or load-balancing. Using a CNAME means that it still works.
Upvotes: 13
Reputation: 135
If you have multiple domain that points to the same site:
With A record: every of your domain points to the IP of your site, when your change your server's IP, you will need to update multiple time.
With CNAME: every of your domain points to a CNAME, when your server's IP change, you will only need to update the A record of that CNAME.
If you have a domain that doesn't belongs to you, or you don't have the control of what it will be pointing to, you can only use CNAME.
Upvotes: 5
Reputation: 179994
It won't really matter if you CNAME
or A
record the *.example.com
record.
The one benefit to CNAME
is that if you change your A
record for www.example.com
you won't need to change the *.example.com
record as well, but that's minimal.
Upvotes: 62