Should I use an A record or a CNAME for a wildcard subdomain?
Asked Answered
B

4

72

Some people are saying use an A record and others a CNAME for a catch all subdomain.

Which should I use and why?

Brutify answered 18/5, 2010 at 21:45 Comment(3)
This isn't an alternative - you need at least one A record in any case. What exactly do you want to do?Slobbery
I think what he means is whether he should create separate A records for mydomain.com and *.mydomain.com OR create one A record for mydomain.com and use a CNAME to alias *.mydomain.com to it.Gustie
@Greg Hewgill He'd have an A record for www/no-www subdomains. He's asking whether he should CNAME * to www or use an explicit A record for it.Fleming
F
60

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.

Fleming answered 18/5, 2010 at 21:51 Comment(5)
Ahh yes, that makes sense nowBrutify
Can this be clarified? The benefit of CNAME is it points to the (already specified) A record instead of an IP? However the benefit of using another A record is that only 1 lookup is performed? If that's the case, surely an A record is the obvious choice, as there's a benefit for every lookup, as opposed to DNS changes which in most cases will be occassional at most? If this is the case I would say it does matter quite a bit.Fluidextract
@Fluidextract Chances are * and www will be on the same DNS server, in which case most DNS servers will return it all in one lookup.Fleming
@Fluidextract this answer is a bit vague. An A record means that if your server's IP changes for some reason, you need to change the A record (this can be bad since it takes up to 48 hours for it to become effective - during which your domain would point to the old ip - which might have gone). A CNAME makes sense when you have an alternative name for your server (or your service provider provides one). In that case, if the IP changes, you won't need to worry about it (unless the provider fked up A records on their side).Justis
For example, if you use a custom domain for GitHub Pages or Cloudflare Pages, they tell you to use a CNAME record pointing to <user>.github.io or <site>.pages.dev respectively, so they can change their infrastructure without having to tell all their clients to switch to a different IP.Justis
E
67

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 and CNAME 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 name blog.myweb.example to point to the server 186.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. The CNAME 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 a CNAME of my.bitbucket.example, which in turns is itself a CNAME of github.map.mybitbucket.example, which is an A record pointing to 186.30.11.143. This means that blog.myweb.example resolves to 186.30.11.143.

Conclusion: A record points a name to an IP address. CNAME record can point a name to another CNAME or an A record.

Source: Differences between A & CNAME records

Eastman answered 24/1, 2017 at 6:18 Comment(2)
should "aestrion.gihub.io" be "my.bitbucket.io"? otherwise i'm confused.Kazoo
@Kazoo I have fixed typo error and updated my answer. Thanks for pointing it out.Eastman
F
60

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.

Fleming answered 18/5, 2010 at 21:51 Comment(5)
Ahh yes, that makes sense nowBrutify
Can this be clarified? The benefit of CNAME is it points to the (already specified) A record instead of an IP? However the benefit of using another A record is that only 1 lookup is performed? If that's the case, surely an A record is the obvious choice, as there's a benefit for every lookup, as opposed to DNS changes which in most cases will be occassional at most? If this is the case I would say it does matter quite a bit.Fluidextract
@Fluidextract Chances are * and www will be on the same DNS server, in which case most DNS servers will return it all in one lookup.Fleming
@Fluidextract this answer is a bit vague. An A record means that if your server's IP changes for some reason, you need to change the A record (this can be bad since it takes up to 48 hours for it to become effective - during which your domain would point to the old ip - which might have gone). A CNAME makes sense when you have an alternative name for your server (or your service provider provides one). In that case, if the IP changes, you won't need to worry about it (unless the provider fked up A records on their side).Justis
For example, if you use a custom domain for GitHub Pages or Cloudflare Pages, they tell you to use a CNAME record pointing to <user>.github.io or <site>.pages.dev respectively, so they can change their infrastructure without having to tell all their clients to switch to a different IP.Justis
S
13

A common use for CNAMEs is to map a subdomain to a host under someone else's control.

In the case of "A" record if they change the IP address you don't need to change your DNS entry.

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.

Schaffer answered 29/1, 2014 at 12:9 Comment(2)
"Using a CNAME means that"...means that what?Delfeena
In the case of "A" record if they change the IP address you don't need to change your DNS entry. - you mean in case of CNAME, right? A records point to IPs.Justis
G
5

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.

Greaves answered 7/10, 2019 at 3:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.