2
votes

Just want to see if I understand this correctly.

CNAME record specifies an alias, in the following form:

alias CNAME canonical-domain

Which means if something is trying to look up alias, it will find the CNAME record and start searching for canonical-domain instead.

A record directly maps a host to an IP

host A IP-addr

So if I have 2 domains eventually pointing to the same IP addr, one is a canonical domain and another is an alias domain, I would use an A record for the canonical domain->IP mapping, and a CNAME record for the alias->canonical mapping.

Why can't I just use 2 A records, one being canonical->IP mapping and the other being alias->IP mapping? Is it so that you only have to update the IP once if you ever need to change it? (Analogy would be CNAME is a softlink and A record is a file in a filesystem)

1
You can use 2 A records, no-one forbids you that. It's even a bit faster as only 1 lookup is required (when with CNAME it is at least 2). In fact -- some records (e.g. MX) require server address (e.g. mail.example.com) to be A record and not CNAME.LazyOne

1 Answers

1
votes

Why can't I just use 2 A records, one being canonical->IP mapping and the other being alias->IP mapping?

You can - that's perfectly normal.

Is it so that you only have to update the IP once if you ever need to change it?

Yes, that's right.

A common configuration is to have the canonical name being the server's real hostname, and then CNAME records for the sites hosted on that server pointing at that.

Note that you can't have a CNAME for a bare domain name (e.g. stackoverflow.com) . A CNAME record can't coexist with the NS and SOA records that are expected to exist at the apex of a zone.

(Analogy would be CNAME is a softlink and A record is a file in a filesystem)

That's not an analogy I'd use.