CNAME vs A Record
The DNS records which live on your domain’s authoritative server are key to the proper functioning of your domain and website. They hold the information that dictates how your domain will handle various requests, which IP addresses are associated with it, and so on. There are many DNS record types, and they vary from being absolutely essential, to simply being quite useful.
Two of the most commonly used DNS records are A records and CNAME records. In a way, A records fall into the category of essential DNS records. A records basically create the link between a website’s IP address (the server where a site’s content is stored) and its domain name (how users access the website through their browsers). CNAME records, on the other hand, aren’t absolutely necessary in theory, but are necessary in practice – if you want your website to be widely accessible, that is. CNAME records create a connection between subdomains or domain aliases and the main IP address for that, whether it’s on your domain or another domain.
Let’s take a closer look at what each of these DNS records is and what their functions are, so as to better understand what the difference between a CNAME and an A record is.
What Is an A Record?
The Domain Name System was created in order to allow users to access websites through their browsers by entering the site’s domain names rather than their IP addresses. Imagine how difficult it would be to keep track of all the websites’ IP addresses. For instance, to visit example.com all you have to do is type that domain name into your browser’s search bar. If the DNS wasn’t instituted, you’d need to type out its IP address, or 184.108.40.206. So rather than having to keep a long list of all website’s IP addresses, we just get to type in their domain names.
The DNS A record serves exactly this basic purpose of the DNS. It contains information about which IP address is associated with a given domain. That’s why the “A” in “A record” stands for “address.” So in the example we gave above, the zone files, or DNS records, concerning the website example.com, have an A record which specifies that example.com lives on the 220.127.116.11 IP address. Without an A record, a website wouldn’t be reachable through its domain name.
So, when a user types out a certain domain into their browser’s address bar, the appropriate server returns the IP address for that domain which is found in its zone files, allowing the user to access the website.
Keep in mind that A records only work with IPv4 addresses, and not IPv6 addresses (you’d use an AAAA record for those).
What Is A CNAME Record?
A CNAME record is a DNS record that provides an association for alias domains and subdomains to the main, parent domain. The “C” stands for “canonical,” as this DNS record connects subdomains to the canonical name-domain or the records delivered for another DNS hostname.
Let’s look at how this looks. When you set up an A record for example.com you associate it with the 18.104.22.168 IP address. However, that doesn’t include domain aliases, such as www.example.com. That’s right, even adding a www before the domain name won’t lead you to the correct website unless a CNAME record exists to provide instructions that those two domains are to result in the same page.
Keep in mind, however, that a CNAME record creates a connection between a subdomain and a parent domain also, which means that it doesn’t always result in the same page popping up. For instance, when you have subdomains for a website, such as blog.example.com or mail.example.com, you still need to create CNAME records that link these subdomains to the parent domain.
Of course, this doesn’t mean that when users try to access a subdomain of that domain they end up on the home page, i.e. the same page as the parent domain. Rather, users are directed to the appropriate files for that subdomain, such as the blog page or the mail page rather than the home page.
CNAME records are quite useful when webmasters change the IP address of their website. Rather than having to change A records for each subdomain, they only have to change the A record for the parent website. Which brings us to…
What Is the Difference Between a DNS A Record and A DNS CNAME Record?
To better clarify the difference between DNS A records and CNAME records, let’s look at an example of how both would work for the same website.
DNS Record Type
As you can see, an A record only serves to associate the parent domain (hostname) with the appropriate IP address. CNAME records, on the other hand, link domain aliases (www) and subdomains (mail) to the parent domain which is specified in the A record. The shop subdomain points to Shopify’s servers, so they can manage which A record (IP address) the online store is hosted on. So while A records connect websites to IP addresses, CNAME records connect subdomains and aliases to the another domain record, not its IP address.
It, therefore, follows that you can’t create CNAME records for the parent (main) domain name, but only A records.
Keep in mind that you should also strive to target all your CNAME records to the parent domain rather than other aliases that are in turn associated with the main domain. This creates an unnecessary additional step in the DNS lookup process, which can cost visitors time and result in needless complications.
For instance, avoid this configuration:
DNS Record Type
Here, mail.example.com is linked to www.example.com, which is in turn linked to the parent domain, example.com. Instead of this, use the configuration we presented above, where all subdomains have CNAME records pertaining to the parent domain (example.com).
A Few Words Before You Go…
Hopefully, our guide has been useful in helping you understand the difference between a CNAME record and an A record in DNS. Both these DNS records types are quite useful, but only A records are absolutely necessary.
However, it’s quite likely that your website won’t function successfully without CNAME records, as well. Even if your website consists of a single page, you’ll at least need to create a CNAME record for www targeting the parent domain.
Additionally, A records connect the parent domain to its IP address, while CNAME records connect domain aliases and subdomains to the parent domain. It’s through the A record of the parent domain that users can access the site’s content. CNAME records can’t be used for creating direct associations with IP addresses.
View Related Articles
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.
Creating a website and publishing it online may sound intimidating. Beginners often worry that they need a lot of technical know-how and a decent level of programming skills to get a website up and running. However, this hasn’t been true for a long, long time.