About
A CNAME (Canonical Name) is a type of DNS record that maps:
- to another absolute name (canonical name).
When a DNS resolver encounters a CNAME record:
- until it found an IP.
Alias
It brings an alias functionality (synonym).
You can achieve the same alias functionality with the alias record but faster because there is only one query needed as the alias record points directly to an IP.
Unicity
CNAMEs are, according to DNS standards, meant to be the only record in a host's DNS records. Therefore, no other record type can be set with the same name.
It means that you shouldn't create a CNAME for your apex domain because the apex domain is generally also set:
- in the MX record in order to receive email
- or other validation TXT records (SPF, …)
Example
On the below domain data, we see:
- a CNAME record
- and a A record
NAME TYPE VALUE
--------------------------------------------------
bar.example.com. CNAME foo.example.com.
foo.example.com. A 192.0.2.23
When a DNS query is performed against bar.example.com, the resolver:
- will get a CNAME record with the value foo.example.com
- will query the domain table again with the value foo.example.com and get an A record
- and will return the IP 192.0.2.23
SEO
To redirect to a name to a server (known as a custom domain), you may use:
- a CNAME
By using a CNAME, the server is not considered as a 1st party server by search engine 1). The script and cookies could be considered as third-party.
Usage
Specification
DNS CNAME records are specified in search/rfc_search_detail.php and clarified in Section 10 of RFC 2181.
Cname as Default record behavior
When a name server fails to find a desired record (RR)
- it checks to see if the resource set consists of a CNAME record with a matching class.
- if so, the name server includes the CNAME record in the response and restarts the query at the domain name specified in the data field of the CNAME record.
See full rule at Section 3.6.2