What Is a CNAME record
A canonical name record (CNAME record for short) is a DNS record that is used to alias a domain name to a different domain name. The domain which is referred to as the canonical name in a CNAME record is the domain on the right-hand side. This domain is the actual canonical name record which resolves information such as IP addresses, subdomains, etc.
The canonical name record becomes useful when you want to direct users to the same information delivered on a separate URL. For example, for website owners who use a domain such as
yourwebsite.com without any subdomain, a canonical name can be used to add www to the beginning of the URL. Therefore, when a user accesses your site via
www.yourwebsite.com, they will see the same information as if they accessed it via
Differences between a CNAME and A record
It is important to know the difference between CNAME and A records and when it is appropriate to use each. The main difference between these two records is that the A record maps a name to an IP address whereas a canonical name record maps a domain name to another domain name. For example:
Within the A record for the example above, example.com points to the IP
22.214.171.124. The CNAME example however uses the
www.example.com subdomain and inherits the resolution chain of the canonical name record which would result in:
www.example.com. CNAME example.com. example.com. A 126.96.36.199
CNAME record limitations
According to the RFC1912, section 2.4, CNAME records have limitations such as:
CNAMEs cannot point to an IP address.
CNAMEs cannot coexist with any other data since they cannot both be an alias and something else.
Both NS and MX records should never map to a CNAME alias. The following configuration should not be used:
example.com. MX 0 mailhost. mailhost. CNAME host.example.com. host.example.com. A 188.8.131.52
Although these limitations partly restrict the usability of canonical name records, there are other methods that can be used to overcome these restrictions.
CNAME usage with the apex of a domain
Based on the limitations mentioned in the section above, a canonical name record cannot be used for aliasing the root domain due to its inability to coexist with other data. However, there do exist some solutions that help overcome this issue.
For example, DNS providers such as DNS Simple or Cloudflare have each implemented their own version of what is called an Alias Record. An alias record essentially allows you to map the root domain to another service while still being able to coexist with other data.
This can prove useful for cases where you would like to map the root domain to a service such as Heroku or GitHub (e.g.
username.github.com) that resolve with a pool of IP addresses. Similarly, an Alias record can be used to point your root domain to a KeyCDN Zone Alias.
Alias records work by masquerading the CNAME record as an A record. This allows you to stay RFC compliant, keeps the underlying A records in sync automatically, and allows the use of the root domain for other DNS records (e.g. MX records or NS records).
CNAME records are a very important and useful DNS record type. Having the ability to alias a custom domain to another service can prove useful whether it be for aesthetic purposes, usability, convenience, and so on. Although they do have some limitations, new methods (such as the ones mentioned above) are great for overcoming those limitations and using the canonical name to alias the root domain.