If you’ve ever wondered how your browser finds its way to the right online destination, you’ve come to the right place. Today we’ll uncover the magic of CNAME records and their role in the world of domain names.
In this article, we’ll delve into the heart of CNAMEs, understanding how they transform aliases into canonical domain names and serve as essential tools within the Domain Name System (DNS) landscape.
📚 After reading it, you’ll have learned:
- What a CNAME record is and its function in the DNS
- How CNAMEs are used
- How to find the CNAME record for any domain name (+examples)
- The restrictions on CNAME records
- CNAMEs and alternative record types
Let’s get started!
What is a CNAME record in DNS?
The table above shows that the domain name blog.examplesite.com (alias) has a CNAME record pointing to examplesite.com (canonical name).
The domain name examplesite.com is associated with an A record, which stands for Address record. This record instructs the DNS server that when someone enters blog.examplesite.com, they should be directed to the IP address associated with examplesite.com, in this case, 192.0.2.0/24.
CNAME record definition (for non-techies)
If you’re a techie, you probably already got what a CNAME record is. But, to make this topic approachable for a less knowledgeable audience, we’ll use an easier example.
Let’s say you have a friend called Sam. He has two nicknames: “Sammy” and “Samson.”
When someone wants to find his home, people use either of these nicknames instead of saying “Sam’s house” every time. They say, “I’m going to Sammy’s” or “I’m going to Samson’s” instead of “I’m going to Sam’s house.”
However, when people say they’re going to “Sammy’s,” they refer to his house porch, where he usually welcomes guests. When people say they’re going to “Samson’s,” they talk about going to his backyard, where he organizes barbecues.
Now, imagine you have a piece of paper with Sam’s house written on it, and you want to share it with your friends so they visit him for his birthday. Instead of writing “Sam’s house,” you can simply write “Sammy’s” or “Samson’s” on the paper. When your friends see these nicknames, they’ll know where to go: both point to Sam’s house.
👉 In this analogy, Sam’s house is a site’s canonical domain name, and the nicknames “Sammy” and “Samson” are domain name aliases pointing to that canonical domain name:
- Sam’s house = site’s canonical domain name.
- Sammy’s = domain name alias with a CNAME record pointing to the site’s canonical domain name.
- Samson’s = domain name alias with a CNAME record pointing to the site’s canonical domain name.
It’s important to note that while CNAME records facilitate this aliasing process within the DNS system, they don’t perform a direct URL redirection. Just think about it: the nicknames “Sammy’s” and “Samson’s” will take you to Sam’s house but to different places. One takes you to his porch and the other to his backyard, but neither takes you inside Sam’s house.
👉 To illustrate, consider a scenario:
- sammy.samhouse.com might have a CNAME that directs to samhouse.com, leading the visitor to samhouse.com’s corresponding IP address.
- Once the visitor connects to that IP address, the web server scrutinizes the URL to identify it as coming from sammy.samhouse.com.
- Subsequently, the web server displays the content associated with the sammy.samhouse.com page instead of the homepage (samhouse.com).
Why are CNAME records useful?
A CNAME record is helpful because, as a website owner, it allows you to associate multiple domain names with a single IP address or hostname.
👉 These are the most common ways to use CNAME records in your site:
- Alias subdomains: use CNAME records to point subdomains to other domains or subdomains, like blog.examplesite.com to wordpress.examplesite.com.
- Network services hosting: assign separate hostnames for network services like email or FTP, directing them to the root domain name. E.g., route services using CNAME records to point ftp.examplesite.com to examplesite.com.
- Multi-country domain registration: register the same domain in multiple countries and point the country-specific versions to the main .com domain. E.g., point domain names like examplesite.co.uk or examplesite.de to examplesite.com via CNAME records.
- Content Delivery Networks (CDNs): redirect users to a CDN by adding the CDN’s address as a CNAME for the origin server, enhancing content delivery. E.g., if you’re using a CDN like Cloudflare, you can set up a CNAME record to point cdn.examplesite.com to Cloudflare’s domain to serve cached content efficiently.
- Migration and redirection: temporarily redirect traffic during transitions using CNAME records. E.g., redirect users from your old site (oldexamplesite.com) to the new one (newexamplesite.com) during a website migration by creating a CNAME record that points the old domain name to the new one.
- DNS management and maintenance: reduce complexity by using CNAME records instead of multiple A records for related subdomains. E.g., instead of setting multiple A records for associated services like api.examplesite.com, app.examplesite.com, and blog.examplesite.com, create CNAME records pointing to a single domain. Then, any changes to the IP address can be managed in one place, simplifying maintenance.
How to find the CNAME record of any domain
👉 The easiest way to find the CNAME record of a domain is by using a CNAME lookup tool:
1. Go to a CNAME lookup tool like whatsmydns.net.
2. Make sure you have the CNAME value selected under the search box.
3. Write a domain name in the search box and press Search.
4. Check the results.
For our example, we checked the CNAME record for www.github.com. The results show that this domain name has a CNAME record pointing to github.com.
⚠️ Important: before checking the CNAME record for a domain name, note that not all domains have CNAME records. These record types are optional and are used for specific purposes, such as the ones described in a prior section of this article.
CNAME record examples
CNAME from subdomain to root domain
In this example, the CNAME record for app.examplesite.com directs to examplesite.com, and the A record for examplesite.com points to the relevant IP address.
CNAME from subdomain to subdomain
Here, the CNAME record for blog.examplesite.com points to wordpress.examplesite.com, and the A record for wordpress.examplesite.com provides the corresponding IP address.
CNAME from subdomain to external domain
The CNAME record for blog.examplesite.com points to the third-party blogging platform’s domain, externalblogplatform.com, and the A record for externalblogplatform.com provides the IP address.
Restrictions on CNAME records
👉 These are the main restrictions or limitations CNAME records have:
- CNAME at the root level: Traditional DNS standards discourage the use of CNAME records at the root domain level, primarily because the root domain is also the DNS Start of Authority (SOA) and is required to have certain types of records that cannot coexist with a CNAME. However, it’s worth noting that some modern DNS providers offer a workaround known as “CNAME flattening.” This feature lets you point your root domain to another domain without violating DNS specifications. Keep in mind, this is not a universally accepted or available option and depends on your DNS provider.
- MX and NS records: According to DNS standards, MX (Mail Exchange) and NS (Name Server) records cannot point to a CNAME alias. MX records are used to specify the mail servers responsible for receiving email messages on behalf of a domain, while NS records designate the authoritative DNS servers for a domain. For the effective functioning of these services, MX and NS records must point directly to A records (for IPv4) or AAAA records (for IPv6).
- Email domain considerations: While you can use CNAME records for various services in your domain, caution is needed when it comes to email services. Specifically, MX and TXT records related to email must point directly to A or AAAA records to ensure the proper functioning of your email exchange and to prevent unexpected issues with various mail servers.
By understanding these limitations and considerations, you can manage your CNAME records more effectively and avoid common pitfalls.
CNAMEs and Alternative Record Types
In this guide, we’ve focused on a specific DNS record type: the CNAME. These are the four other major DNS record types:
An A record maps a domain name to an IP address, directing users to the correct server for a website or service.
An AAAA record maps a domain name to an IPv6 address, enabling connectivity for users accessing websites via IPv6.
IPv6 is the latest version of the Internet Protocol.
An NS record specifies the authoritative name servers for a domain, guiding DNS queries to the correct source for domain information.
Put simply, the NS record guides web browsers and similar internet applications to the place where they can discover the IP address linked to a domain name.
An MX record shows which servers handle emails for a domain, making sure the servers deliver emails correctly.
So, as we’ve learned today, CNAME records do a very important job: they point domain aliases to IP addresses to help your browser understand where to go.
Now that you’re well-versed in CNAME records, you’re one step away from optimizing your domain management strategy, transforming aliases into canonical domain names, and simplifying DNS management.
Just remember that CNAME records aren’t merely technical tools. They’re your allies in crafting a seamless online presence. 💡
👉 For more insights on DNS, check out our article on DNS load balancing and why it matters.