A CNAME record or Canonical Name record is a type of resource record in the Domain Name System (DNS) that specifies that the domain name is an alias of another, canonical domain name. This helps when running multiple services (like an FTP and a webserver; each running on different ports) from a single IP address. Each service can then have its own entry in DNS (like ftp.example.com. and www.example.com.). Network administrators also use CNAMEs when running multiple HTTP servers on the same port, with different names, on the same physical host.
DETAILS
CNAME records are specified in RFC 1034. CNAME records are handled specially in the domain name system, and have several restrictions on their use. When a DNS resolver encounters a CNAME record while looking for a regular resource record, it will restart the query using the canonical name instead of the original name. (If the resolver is specifically told to look for CNAME records, the CNAME alias is returned, rather than restarting the query.) The canonical name that a CNAME record points to can be anywhere in the DNS, whether local or on a remote server in a different DNS zone.
For example, if there is a DNS zone as follows:
foo.example.com. CNAME bar.example.com.bar.example.com. A 192.0.2.23
When an A record lookup for foo.example.com is done, the resolver will see a CNAME record and restart the checking at bar.example.com and will then return 192.0.2.23.
Which is the "CNAME"?
RFC 2181, "Clarifications to the DNS Specification", includes a warning on the use of the word "CNAME". "The CNAME" or "a CNAME" is often used to refer to the label, or left-hand part, of a CNAME record. However, as "CNAME" is an abbreviation of "canonical name", this usage is inaccurate; the label is an alias for the right-hand side (the RDATA portion), whichis (or should be) a canonical name.[1] In other words, a CNAME record like this:
foo.example.com. CNAME bar.example.com.
may be read as:
- foo.example.com is an alias for the canonical name (CNAME) bar.example.com.
The canonical name itself must be defined by a record other than a CNAME or DNAME record.
Restrictions
- An alias defined in a CNAME record must have no other resource records of other types (MX, A, etc.). (RFC 1034 section 3.6.2, RFC 1912 section 2.4) The exception is when DNSSEC is being used, in which case there can be DNSSEC related records such as RRSIG, NSEC, etc. (RFC 2181 section 10.1)
- CNAME records that point to other CNAME records should be avoided (RFC 1034 section 5.2.2). In particular, it is possible to create infinite loops with CNAME records, and other error conditions, as:
foo.example.com. CNAME bar.example.com.bar.example.com. CNAME foo.example.com.
- Other DNS record types, such as NS, MX, PTR, SRV, etc. that point to other names should never point to a CNAME alias. (RFC 1034 section 3.6.2, RFC 1912 section 2.4) So, for example, a zone should not contain constructs such as:
example.com. MX 0 foo.example.com.foo.example.com. CNAME host.example.com.host.example.com. A 192.0.2.1
No comments:
Post a Comment