Weโve previously talked about how the Domain Name System (DNS) works, but this isnโt the whole picture. There are lots of additional cogs that make up the wheel, and so far we havenโt discussed some of the most common elements, such as CNAME records.
For this article, weโll answer the question of what a CNAME record is, and show you several variants that you can use. Then weโll talk about the limitations youโll experience, and finally show you how to add them for your domain.
Letโs get to it!
Subscribe To Our Youtube Channel
What Is a CNAME Record?
At its core, the DNS works by mapping domain names to specific IP addresses. When you type a URL in your browser, it looks up the corresponding IP address through the DNS and leads you to the website you want to visit.
However, this is just one type of record the DNS uses. With CNAME records, you can map URLs as aliases to your canonical domain. This means if the IP address mapped to that canonical domain changes, your CNAME records will stillย work because they point to the root domain.
To offer a real-world example, letโs say you have these three URLs:
- yourwebsite.com
- www.yourwebsite.com
- yourwebsite.io
URL number one would be your siteโs canonical domain, which points towards your siteโs IP address. In practice, youโd need to set up a CNAME record that redirectsย www.yourwebsite.comย visitors towardsย yourwebsite.com.
At the same time, we also have the same name registered using a different Top-Level Domain (TLD). This means youโd want to create a second record that redirects address three towards number one. All of that usually happens through your domain registrar or whichever service you use to manage the URLs that you โownโ.
2 Examples of CNAME Records
In fact, CNAME entries come in many shapes and sizes. However, in most cases youโll only need to set up one CNAME record for a new website โ typified by the wwwย example we just mentioned.
In a later section, weโre going to show you how to set up a similar record through your registrar. First, letโs go over three more examples in closer detail.
1. Setting Up Separate Hostnames for Services Such as File Transfer Protocol (FTP) or Email
If you want to access your website via FTP using a domain such asย ftp.yourwebsite.com, youโll need to set up a corresponding FTP CNAME record:
This same approach applies to CNAME records for additional services that you use, such as email. Here, youโd want to set a โhostnameโ such as โmailโ instead:
Those records would correspond to the following two URLs:
- ftp.yourdomain.com
- mail.yourdomain.com
With most registrars, you can either enter the full hostname (those two URLs you see above) or an abbreviation such asย www,ย ftp,ย andย mail.
2. Pointing Addresses With Different TLDs Towards a โMainโ Domain
In some cases, it pays off to register the same domain name using different TLDs. For example, you can set up a CNAME record for yourdomain.orgย that points towardsย yourdomain.com.ย Hereโs how the record would look:
Itโs important to understand that you need to add this type of CNAME record to the domain you want to point towards a different URL. In other words, you canโt point a root level domain towards another using a CNAME record. Root domains, such asย yourdomain.comย need to be mapped towards an IP address.
Using this same approach, you can map entirely different domains to a root URL. Letโs go over how the mapping process works, so you know where to start.
How to Add CNAME Records For Your Domain
Adding new CNAME records works largely the same with most registrars, although the interface that each one uses might be different. To show you how this works, weโre going to set up a basic record to point a wwwย URL towards its canonical domain. For starters, youโll want to open your domainโs settings through your registrar.
For example, if youโre using Namecheap, the registrar includes an Advanced DNSย tab for each domain you own. Within the tab, you can add multiple types of records (there are more options beyond CNAME!).
In the example below, you can see an โAโ record. This is a type of record that maps your canonical domain towards your siteโs IP address.
To add a record, youโd need to click on ADD NEW RECORDย and selectย CNAME Recordย underย Record Type:
Underย Hostย you need to enter theย wwwย prefix for this particular example. Now add your websiteโs canonical domain underย Target:
Finally, thereโs one last setting calledย TTL. This acronym stands for โTime to Liveโ and it tells your nameservers how often they should update your DNS records. As you might know, DNS records take some time to โpropagateโ and become accessible globally. The lower your TTL time is, the shorter the wait should be.
In most cases, we recommend leaving this setting to Automaticย as DNS records usually propagate fast enough. For now, save your new record, which should appear under its A sibling:
Keep in mind that you can set up multiple CNAME records depending on your needs. In the previous section, we explored multiple options, and all of them can be set up concurrently.
What youย canโtย do is set up records that direct the same domain towards different canonical URLs. This means you couldnโt set up two records pointing www.yourdomain.comย towardsย yourdomain.comย andย alternatedomain.com. If youโre setting up a new website, most times youโll only need to create two records for everything to work. Those would be one A and one CNAME record.
Conclusion
CNAME records are a core component of the DNS. If you need to point domains towards one another (instead of towards an IP address), youโll need to use CNAME records.
There are several uses for CNAME records, but two of the most common uses include:
- Setting up separate hostnames for services such as FTP or email.
- Pointing addresses with different TLDs towards a โmainโ domain.
Do you have any questions about how to use CNAME records? Letโs talk about them in the comment section below!
Article thumbnail image by DiA99 / shutterstock.com
I have a question – I am changing my hosting from blogspot to blue host, so can I keep the same CNAME in the domain DNS settings or delete it..
Hi Patrika! I would contact BlueHost support and ask if there’s anything you need to do here. That way you know you’ll be getting an answer tailored to the platforms you’re working with.
As a web host, I suggest that using a CNAME record for mail.example.com might end up leading to confusion.
It is not at all uncommon to have DNS hosting plus email at one service and a website at another e.g. Squarespace, that doesn’t provide email. In this case the A record and MX records need to be different. The MX will need to point to (for example) mail.example.com and in turn that will need an A Record, not a CNAME.
While I understand this blog is targetted at WordPress users the information is useful for everyone and should take them into account.
Thanks for your insight, Steve!
Thanks for the article. Could you write one that goes through every single step in excruciating detail for separating the mail to go to gmail.com, outlook.com, and a couple more of the most popular business mail providers? The one I saw earlier didn’t go into how to set the whole thing up on a particular service.
Glad you liked the article! Thanks for your suggestion โ it would be an interesting post to write. I’ll pass it along.
Can I use Cname recotds to map domains to a subdomain? This question is in regards to setting up a WordPress multi-site.
Yes, Clay, you absolutely can use CNAME records for subdomain mapping! If you do a quick Google search, there are many tutorials for this available.