Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between an A Rec and CNAME in Route53

As Amazon Route 53 allows you to set an A record or a CNAME to a different sub-domain name using Alias, I am wondering what is the difference between A record and CNAME now.

To clarify my question, the difference between CNAME and A record in a traditional NameServer is that only CNAME can be used to point to a different subdomain and A record must point to a valid IP address. Since the AWS Route53 allows you to do use a subdomain with either A Rec or CNAME .. does it not blur the distinction between the two.

like image 283
Scalable Avatar asked Jun 19 '13 14:06

Scalable


People also ask

What is the difference between CNAME and a record in Route 53?

To clarify my question, the difference between CNAME and A record in a traditional NameServer is that only CNAME can be used to point to a different subdomain and A record must point to a valid IP address. Since the AWS Route53 allows you to do use a subdomain with either A Rec or CNAME ..

What is the difference between an A record and a CNAME?

An A Record maps a hostname to one or more IP addresses, while the CNAME record maps a hostname to another hostname.

What is the difference between a record and CNAME in AWS?

The A record maps a name to one or more IP addresses when the IP are known and stable. The CNAME record maps a name to another name. It should only be used when there are no other records on that name. The ALIAS record maps a name to another name, but can coexist with other records on that name.

What is an A record in Route 53?

Amazon Route 53 offers a special type of record called an 'Alias' record that lets you map your zone apex (example.com) DNS name to your Amazon CloudFront distribution (for example, d123.cloudfront.net).


1 Answers

Your question is quite valid, but you are using the word "subdomain" in a not-quite-precise way.

What you are actually asking is about the fact that an Route 53, an A record can give the appearance of referencing either a fully-qualified hostname from another domain, or a hostname or subdomain from its own domain, while in proper DNS, the only way to reference another hostname is with a CNAME, yet those can't be provisioned at the apex of a domain ("example.com") pointing to a subdomain ("www.example.com").

An alias, you're saying, seems to be functionally equivalent but more flexible than a CNAME so is there a difference?

The difference between a CNAME and an alias is that a CNAME is still a proper, standard, ordinary DNS CNAME, which returns a DNS query response "hi, you need to know that the real ("canonical") name of the server you are looking for is 'x'" and, depending on circumstances, may also include the A record for the target host or may not, requiring the client to go for a second lookup.

Aliases, on the other hand, are a clever hack created by Amazon which does not break the protocol yet allows Route 53 to hand out the A record directly from resource "X" when the A record for resource "Y" is requested. Aliases can also reference other record types, but the record type they reference must be the same and for the purposes of this discussion, I am talking about A record aliases.

And, the important take-away here is that an alias actually returns an A record -- not a reference to the target, like a CNAME does.

The catch is that with an alias, you cannot put just any hostname in that box. It has to be a hostname within a domain where Route 53 has the magical hooks so that it can retrieve the apprpriate A record to serve up -- either another entry in your zone, or from S3, ELB, or Cloudfront. This is a very different implementation than how CNAME records work, even though the net effect appears to be the same.

Put anything else in there, and The record set could not be saved because:- Alias Target contains an invalid value. Try it. :)

Of course, CNAME records have no limitation like that... they're just limited by design in their use at the top of a zone.

So, in fact, Aliases and CNAME records do not have as much overlap as you may have initially thought. In some situations, only one is usable, and cases where either one would work, the difference is probably insignificant.

One advantage of Alias in the case where either one could be used is that an alias never requires 2 DNS queries, as I mentioned above. It is always answered directly by Route 53 with the appropriate A record, where a CNAME, at least in the case where it references a hostname in a different top level domain, can require two sequential DNS lookups, giving Alias a theoretical performance advantage in that case.

like image 164
Michael - sqlbot Avatar answered Oct 02 '22 10:10

Michael - sqlbot