At the beginning of working with an online resource, everyone is faced with DNS records. We have already talked about how the Domain Name System works, but today we are going to discuss one of the records - CNAME (canonical name) and the purpose of CNAME.
A CNAME record, or canonical name (cname) record, is a DNS record used to map one domain name to another. In other words, canonical names and aliases.
The CNAME record format:
mail.myfirstwebsite.com CNAME myfirstwebsite.com
The answer to a canonical name query might look like this:
mail.myfirstwebsite.com canonical name = myfirstwebsite.com
Canonical name in DNS can be presented as follows (canonical name examples):
Domain (subdomain) / Host |
DNS Record |
Destination |
myfirstwebsite.com |
A |
3.3.3.3 |
www.myfirstwebsite.com |
CNAME |
myfirstwebsite.com |
mail.myfirstwebsite.com |
CNAME |
myfirstwebsite.com |
ftp.myfirstwebsite.com |
CNAME |
myfirstwebsite.com |
CNAME makes it easy to use multiple services (for instance, ftp or mail) from the same IP address. If you change the IP, you need to set up only the A record.
There are also ANAME and DNAME records. ANAME, also known as ALIAS, is an alternative to CNAME with its own advantages. DNAME record provides redirection from one part of the DNS name tree to another (for example, to redirect traffic from the old myfirstwebsite.com to the new myfirstwebsite.org).
When you enter mail.mywebsite.com into the address bar, the DNS server starts searching for the A record. After the CNAME record is found, the query is restarted and the canonical domain name (myfirstwebsite.com) is used instead of the original one (mail.myfirstwebsite.com.). This happens because mail.myfirstwebsite.com is a subdomain of myfirstwebsite.com. As a result, the required IP address will be found through the A record of myfirstwebsite.com.
The query can be set to search for CNAME records first. In this case, the response will be the canonical name (cname), not the IP.
Use cases of the CNAME (canonical name) are not limited by this list. CNAME record used for various tasks:
When writing the CNAME record, you should consider the following restrictions:
Let's create a canonical name (cname) record:
We remind you, it can take up to 72 hours for new records to work.
On the Internet, you can find services called CNAME Lookup. These services, after entering the domain, will provide a list of CNAME records in order of priority.
Some tools allow you to see not only CNAME, but also other records:
Another way is to use the nslookup application, which is available on Windows, MacOS, and Linux.
So, to check the CNAME on MacOS or Linux, start a terminal. On Windows, you need to run the command line (Start → Run, type cmd and press Enter).
Then enter the command with the desired subdomain:
nslookup -q=cname mail.myfirstwebsite.com
The app will give you information:
Server: 3.3.3.3
Address: 3.3.3.3#73
Non-authoritative answer:
mail.myfirstwebsite.com canonical name = myfirstwebsite.com.
That is, mail.myfirstwebsite.com points to the canonical name (cname) myfirstwebsite.com.
In the domain name system, CNAME, A, and ALIAS records may look similar, but you should know their key differences. Owners of websites or other online projects are faced with each type of record during the initial work with domains.
The difference between A record and CNAME record is that A record is used to map a root domain to an IP address. This is the main difference because in the CNAME record, you can only map one domain (mail.myfirstwebsite.com) to another (myfirstwebsite.com.). Subdomains with CNAME records cannot have A records.
Just like the CNAME, the ALIAS maps one domain to another. However, CNAME doesn't allow adding other resource records for these domains. But with ALIAS, it is possible. Also, an ALIAS query immediately returns an IP address, without mediating with another domain name. This reduces the processing time for the query.
Redirect and CNAME are not directly related. To create a redirect, you need to configure the server so that it will give a specific response for a specific HTTP request. CNAME cannot guarantee it.