Difference between an A Rec and CNAME in Route53

假装没事ソ 提交于 2019-12-02 17:16:25

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.

I think you have wrong information. Amazon Route53 doesn't allow A records with subdomains. When I'm trying to set it to a domain name I'm getting an error:

The record set could not be saved because:
- The Value field contains invalid characters or is in an invalid format.

A records are for IP addresses only.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!