Now we will check one of the basic DNS records – CNAME. Why do you need CNAME records, how to use them, and are there any alternatives? You are about to find out!
What is a CNAME DNS record?
CNAME, the “c” stands for “canonical”, and the rest is “name”. You can use it to show that one domain name is just another way of showing another domain (it is an alias for the canonical domain). The canonical means it is the “true” domain name.
See this example, www.ThisIsMySite.com has a redirect to ThisIsMySite.com (without the first part of www.).
A very common approach is to set a CNAME record that determines that a specific subdomain is an alias for the root domain, which is canonical.
A very important note here, the CNAME records are used exclusively for subdomains!
If a particular host gets a CNAME, you can’t add any other DNS record for it!
And visa-versa, if there are previously added DNS records for the host, you can’t add a CNAME DNS record.
If you have a situation when you need to have more DNS records and still perform the same function as the CNAME record, you will need another DNS record called ALIAS.
Use cases of CNAME records
- Point regular subdomains and subdomain for services like FTP or email to the main host.
- CNAME can be used for Content Delivery Networks (CDN) to balance the traffic better. A query for the original server can be pointed to a CNAME that is a part of the CDN and give back a result that will best fit the user.
- If an organization has multiple websites, you can use the CNAME records and point them to a single one.
- If you have .es, .it, .eu, and more domains registered, you can unite them to a single spot, that is .com.
How does a CNAME look?
The CNAME record has a very simple look with just a few elements:
- Host – host’s name. This is the subdomain that you want to point.
- Type – CNAME. Just definition of the type of DNS record.
- Points to – here you set the canonical name.
- TTL – Time to live for the record.
Why do you need a CNAME?
You need a CNAME DNS record to point multiple different hosts to the same point. That way, they will update easily. When you change the DNS records for the canonical name, the rest will get the data from there.
An example of this is if the IP address of the “true” domain changes, the A or the AAAA record will change in the canonical, but the rest will auto-update and still lead to the proper address.
CNAME record vs A record
The CNAME will point a host, usually a subdomain, to another host.
The A record is pointing a host to an IP address.
CNAME vs ALIAS
The ALIAS record can serve the same purpose as the CNAME but in another way.
An advantage of the ALIAS is that it can coexist with other DNS records, while CNAME can’t, and you can use ALIAS for the root domain too. This is impossible for the CNAME record.
The ALIAS is quite faster because it returns an IP address directly, while the CNAME will return an answer that shows the true hostname, and then a second query must be performed to get the IP address.
I hope you get all your doubts about CNAME resolved here. If you want to know more about DNS records, you can find more articles in this blog.
Recommended article: Dynamic DNS (DDNS) – Why use it?