Difference between an A Rec and CNAME in Route53

前端 未结 2 1895
悲&欢浪女
悲&欢浪女 2021-01-30 16:26

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.

2条回答
  •  醉梦人生
    2021-01-30 17:09

    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.

提交回复
热议问题