What Is a CNAME Record?
For people to enjoy the simplicity that comes with using the internet – like visiting a website, for instance – a lot goes on behind the scenes. For you to visit a website, all you do is type in its domain name. What makes it possible for you to reach that website by just typing in the domain name are DNS records. But that’s just one purpose of DNS records – there are many more.
DNS records, or zone files, are the instructions located in authoritative DNS servers which contain details about a domain, such as the IP address of that domain and how to manage requests about that domain.
Some types of DNS records have essential purposes, and without them a website couldn’t function properly. Others aren’t technically necessary in all cases, but most websites wouldn’t be able to function without them. One of the most commonly used DNS records – which falls in the second category – is a CNAME record. Let’s take a look at what a CNAME record is, how it works, and what it’s used for.
What Is a CNAME Record?
A CNAME record (stands for “canonical name” record) is a DNS record which is used to connect an alias of a domain (or a subdomain) with the main domain.
In other words, it takes visitors arriving at the alias domain to the same website which is associated with the main domain itself. CNAME records don’t point to IP addresses, instead they point to another hostname. This especially comes in handy when webmasters change the IP address of their website. Rather than having to reconfigure the settings for all domain aliases, they only have to reconfigure which IP address the DNS A record is associated with.
Let’s look at some examples of how CNAME records work, so as to better understand what they are.
How Does a CNAME Record Work?
When a visitor tries to access your website, they type in its domain name. The DNS A record is responsible for connecting the domain name with the website’s IP address so that the visitor can see your site’s content. However, let’s say your domain name is example.com, but the visitor types in www.example.com. In this case, they won’t be able to reach your website unless there’s a CNAME or A record that has specified that users trying to access the www.example.com alias would actually get the content of example.com, i.e. the original website.
So in this case, example.com is the domain which the A record associates with the site’s IP address. The other domain, www.example.com, is the alias domain. The CNAME record serves to point visitors trying to reach the alias to the main domain which is connected to the IP address. Picture it like this:
- An A record points the main domain’s website (for instance, example.com) to its IP address (like 22.214.171.124). This allows visitors to access the site’s content by typing in the domain name rather than the IP address, thus keeping things plain and simple.
- If a visitor tries to access the website through an alias, a CNAME record points the domain alias (www.example.com) to the main website (example.com).
- Once the visitor lands on the main site, the A record allows for its content to be retrieved by associating it to the appropriate IP address.
What Are CNAME Records Used For?
There are several frequent uses of CNAME records. In all cases, using a CNAME comes in handy if you change your IP address or server.
One important use, which we’ve covered in our example, is using a CNAME record to create an alias that contains www before the usual domain.
Another use is to point various subdomains to the same host name. For instance, you can point several subdomains (or aliases) – such as mail.example.com or blog.example.com to example.com, which basically points them to the appropriate IP address.
Keep in mind that a CNAME doesn’t always result in the same site as the main domain. Although this would be the case for the first use (www), it wouldn’t be true for the second use we talked about (mail.example.com and blog.example.com). The CNAME record will point the visitor to the same IP address (via the A record, not directly) as the root domain, but not the same exact website. So mail.example.com would take the client to the mail service of the website, but it would still be directed to the IP address associated with the root domain.
We include free DNS hosting with all domain registrations at Domain Name Sanity, along with email forwarding and URL forwarding.
View Related Articles
Emailing today is such an easy task. Compose, hit send, and your message travels across oceans and borders to reach its recipient. It is such an easy task that people’s attention starts to drown in their full inboxes, which are also littered by spammers, phishers and other members of the not-so-nice population of netizens.
But what are redirects, and why are they important? What are the different types of redirects? We’ll fill you in on everything you need to know about redirects, and most importantly – how to do them on your WordPress site.
What are the benefits of opting for a dedicated IP? And perhaps most important of all – do you really need one? Let’s take a closer look at all the questions surrounding dedicated IPs so that you can better understand who needs a dedicated IP and when.