Canonical Name Records, or CNAME records, are usually referred to as alias records since they usually map an alias to its canonical name. The name server does handle these queries differently from an A record. When a name server looks up a name and finds a CNAME record, it replaces the name with the canonical name and looks up the new name. This allows you to point multiple systems to one IP without specifically assigning an A record to each host name. If your IP was ever to change you would only have to change one A record.
For example, if you had the following A record:
Name - dnsuniversity.com
TTL - 1800
IP - 192.168.1.2
You could make the following CNAME record:
Name - mail.dnsuniversity.com
TTL - 1800
Data - dnsuniversity.com.
Both records point to the same IP, but the IP does not need to be specified in the CNAME record.
There are some restrictions as defined by the RFCs:
- CNAMEs must have no other resource records of other types (MX, A etc) as specified by RFC 1034 section 3.6.2 and RFC 1912 section 2.4. The exception is when DNSSEC is being used, in which case there can be a DNSSEC related recrd such as RRSIG, NSEC, etc. (RFC 2181 section 10.1)
- CNAME records that point to other CNAME records should be avoided. In particular, it is possible to create infinite loops with CNAME records, and other error conditions. RFC 1034 section 5.2.2. For example:
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. RFC 1034 section 3.6.2, RFC 1912a> section 2.1. So for example, a zone should not contain constructs such as:
foo.example.com. CNAME host.example.com. host.example.com. A 192.0.2.1 example.com. MX foo.example.com.
DNAME Records
A DNAME record or Delegation Name record is defined by RFC 2672. A DNAME record will delegate an entire portion of the DNS tree under a new name. In contrast, the CNAME record creates an alias of a single name. Like the CNAME record, the DNS lookup will continue by retrying the lookup with the new name. If a DNS resolver sends a query without EDNS, or with EDNS version 0, then a name server synthesizes a CNAME record to simulate the semantics of the DNAME record.
For example, if there is a DNS zone as follows:
foo.example.com. DNAME bar.example.com. bar.example.com. A 192.0.2.23 xyzzy.bar.example.com. A 192.0.2.24
An A record lookup for foo.example.com will return 192.0.2.23, just as if the DNAME was a CNAME. However, unlike a CNAME, a lookup for xyzzy.foo.example.com will return the A record for xyzzy.bar.example.com which is 192.0.2.24.