Now we’ll look at one of the most common DNS record types: CNAME. What is its purpose, and how do you use it? You’ll find out soon!
CNAME record – what does it mean?
The name of the CNAME is split into two pieces. The letter C stands for canonical, and it indicates which domain name is the true one for the one you’re trying to resolve. The NAME is self-evident. Name, as in hostname, is what it stands for.
The CNAME record’s function is to point one hostname to another. So, you can use the domain name to point to different subdomains. You won’t need to create any other records for the subdomain because it will automatically redirect the domain name.
You will have far fewer DNS records if you only have a single DNS record for each subdomain, and domain administration will be much easier.
For example, we can use CNAME records to direct traffic to:
www.DNSdomain.net to DNSdomain.net
info.DNSdomain.com to DNSdomain.com
How to set it up?
This is most often a paid service. So, it would be best to look for a good DNS hosting provider that offers it. The structure of CNAME record itself is very simple and has the following form:
- TYPE – CNAME
- HOST – www.DNSdomain.net – the name of the subdomain you’d like to point to the main domain
- POINTS TO – DNSdomain.net – the domain name
- TTL – 1m – time-to-live
Why do you need it?
To point numerous hosts to the same location, you’ll need a CNAME DNS record. That way, they’ll be able to update quickly. When the DNS records for the canonical name are changed, the rest of the system will obtain the data from there.
If the IP address of the “true” domain changes, the A or AAAA record in the canonical will change, but the rest of the records will automatic update and still point to the correct address.
Restrictions of CNAME record
- A Canonical Name record should always point to another domain name rather than an IP address.
- Because of the way this record works, you can’t establish a CNAME record if the host (subdomain) already has other DNS entries like A, MX, and so on.
- You can’t construct any other type of record in the zone until you first create a CNAME record.
- Although CNAME records can point to other CNAME records, this is not recommended because it is inefficient. The CNAME should point as closely as feasible to the destination name to prevent needless performance overheads.
CNAME record vs. A record
The CNAME and A records are really different types. The CNAME record connects one hostname to another, whereas the A record connects a domain name to an IP address. Also, if you want to resolve a domain and first obtain a CNAME, you will also require the A record. As a result, the CNAME will require two queries rather than one.