Select the Gcore Platform

Gcore Edge Solutions
Go to Gcore Platform →
Products:
  • Edge Delivery (CDN)
  • DNS with failover
  • Virtual Machines
  • Bare Metal
  • Cloud Load Balancers
  • Managed Kubernetes
  • AI Infrastructure
  • Edge Security (DDOS+WAF)
  • FaaS
  • Streaming
  • Object Storage
  • ImageStack (Optimize and Resize)
  • Edge Compute (Coming soon)
Gcore Hosting
Go to Gcore Hosting →
Products:
  • VPS Hosting
  • Dedicated Servers
  • SSL Certificates

Share

What Are DNS CNAME Records? | How They Works, Use Cases, and Importance

CNAME records are an important tool in the world of business branding and website management that serve multiple purposes. For one, think of the subdomains “store.example.com” or “blog.example.com”—these represent distinct sections of a website that provide specific content types to visitors. Creating subdomains like “store” or “blog” is made possible by using CNAME records. Another use of CNAME records is to enable the use of content delivery networks (CDNs), which improve page load times and user experience. In this article, we will delve into how CNAME records work, explore their use cases, and learn best practices for implementing CNAME records.

What Is a CNAME Record?

CNAME, short for canonical name, is a type of DNS (Domain Name System) record. A CNAME record is used in two contexts:

  • To make a subdomain that directs to a different server
  • To send visitors from one domain to another

Let’s start with the first context. Imagine you have an online store and you want to create the subdomain “shop.example.com.” You can create a CNAME record to point to the main domain (example.com) or to a different source such as a third-party website using their provided URL. For instance, if you have a Shopify account, you can use a CNAME record (shop.example.com) to send your customers to your Shopify website (shops.myshopify.com).

In the second case, a CNAME record is used as a pointer or alias from one domain name to another. It allows you to associate one domain name with the IP address of another domain name. In simpler terms, a CNAME record is like a nickname or shortcut for a domain.

What Are the Components of a CNAME Record?

Here is a table with an example of a CNAME record:

HostnameRecord TypeValueTTL
www.example.comCNAME@ (example.com)1800 seconds
blog.example.comCNAMEblogalias.com3600 seconds
mail.example.comCNAMEdomainverify.googlehosted.com3600 seconds

Let’s examine each of these components and their functions in detail.

  • Hostname. The hostname is an identifier or a unique label to identify and differentiate devices within a network. In the Domain Name System (DNS), a hostname is commonly associated with a domain name. For example, in the domain name “www.example.com,” “www” is the hostname representing a specific server or service within the “example.com” domain. The hostname helps to route network requests to the appropriate device or server. Beyond websites, it can also be used to access resources such as email servers, FTP servers, or any other network-connected device.
  • Record type. The record type for CNAME records is always set to “CNAME” so that the DNS resolver can identify it as such. This allows the resolver to follow the alias and resolve the canonical name, retrieving the corresponding IP address or other server type.
  • Value. This represents the destination or target where the DNS resolver should redirect the queries for the specified hostname. For instance, if you need to verify your domain name in Google, you need to add a CNAME record with the unique value that they provide such as “domainverify.googlehosted.com.”
  • TTL (time to live). The TTL value for a CNAME record determines the length of time that DNS resolvers and caching servers should cache the record before checking for updates. It is specified in seconds. For example, a TTL of 3600 represents one hour of cache time.

Use Cases of CNAME Records

CNAME records provide flexibility in directing traffic, setting up subdomains, or implementing third-party services. Whether redirecting domains, managing content delivery networks (CDNs,) or facilitating email services, CNAME records empower website owners to customize and optimize their online presence, whatever their business type or size. Let’s look at some of the use cases of CNAME records in more depth.

Domain Redirection

CNAME records can redirect traffic from one domain to another, making it easy to switch between websites or redirect visitors to a different online location. When a CNAME record is created for a domain, it acts as an alias or nickname, allowing the source domain to point to the same IP address as the target domain.

Example: John’s Apparel, an online clothing retailer, decided to rebrand its website and switch to a new domain name, “new-johnsapparel.com.” To ensure a seamless transition, the company will set up a CNAME record for the old domain, “old-johnsapparel.com,” redirecting users to the new website. When users type “old-johnsapparel.com” into their web browsers, the CNAME record directs them to the new website. Users don’t need to learn or remember a new URL, which eliminates any potential loss of business when changing domain names.

Here’s a sample CNAME record for domain redirection:

TypeHostnameValue
CNAMEold-johnapparel.comnew-johnapparel.com

Subdomain Setup

CNAME records are frequently used to make subdomains that direct to separate servers or services. This helps organizations to arrange and handle specific parts of their website independently.

Example: ABC Corporation is a software development company with numerous services and departments. It wants to organize and manage its different services under specific subdomains. For instance, a subdomain “support.abc-corp.com” needs to be pointed to “support-target-server.com” for their customer support portal. This allows them to handle different parts of their business independently while maintaining an online presence with great UX.

Here’s an example CNAME record for subdomain setup:

TypeHostnameValue
CNAMEsupport.abc-corp.comsupport-target-server.com

Content Delivery Network (CDN)

CNAME records can be used to integrate CDNs, which cache and distribute website content across multiple servers, enhancing website performance and global accessibility.

Example: Shoes & More is an online store that sells a wide variety of footwear products and accessories to customers globally. They have experienced significant growth, resulting in high website traffic and the need to optimize their website’s performance and loading speed. The company decided to integrate a CDN to enhance its website’s performance. To achieve this, they signed up for a CND service and they were advised to set up a CNAME record.

Here’s an example CNAME record for content delivery network:

TypeHostnameValue
CNAMEshoesandmore.comcdn-provider-example.com

Email Service

CNAME records enable domain owners to configure email services from third-party providers. For instance, by creating a CNAME record you can associate your domain’s email subdomain (e.g., “mail.example.com”) with a dedicated email service provider like Google or Microsoft.

Example: Handmade Crafts & Treasures is a small e-commerce business that sells handmade crafts and artisanal goods online. They want to enhance their email communication by using a professional email service, so they decide to sign up for a third-party email service provider. To set it up, they need to create a CNAME record for the new email service.

Here’s an example CNAME record for email service:

TypeHostnameValue
CNAMEmail.handmadecrafts-treasures.commail.provider.com

Third-party service integration

By leveraging CNAME records, organizations can effortlessly integrate third-party services such as e-commerce platforms, customer support systems, or analytics tools, ensuring a seamless user experience. For instance, if you need to use Google Analytics for your website, you need to add a CNAME record to your DNS records to verify your domain name.

Example: XYZ Goods online store is an e-commerce business that sells a wide range of products through its website. They want to integrate Google Analytics to gain valuable insights into their website traffic and customer behavior. To achieve this, they need to add a CNAME record to their DNS records to verify their domain name for Google Analytics.

Here’s a CNAME Record for a third-party service (Google Analytics) integration:

TypeHostnameValue
CNAMEwww.xyz-goods-onlinestore.comanalytics.google.com

How Does DNS Manage and Resolve CNAME Records?

Managing and resolving CNAME records requires the use of DNS, which stands for the Domain Name System.

User visits shop.example.com, DNS resolver interacts with DNS root servers, TLD DNS server and authoritative DNS server resolve CNAME
How DNS manages and resolves CNAME records

Here are the steps used by DNS to manage and resolve CNAME records:

  1. User sends a request. The process begins when a user sends a request, such as entering a website’s URL into their web browser.
  2. DNS resolver. The user’s device, typically operated by the internet service provider (ISP) or a public DNS provider, acts as the DNS resolver. The DNS resolver is responsible for handling DNS queries and resolving domain names into IP addresses.
  3. DNS root servers. If the DNS resolver does not have the requested information in its cache, it initiates a DNS query by sending a request to the root DNS servers. The root DNS servers are the starting point of the DNS resolution process and are responsible for providing information about the top-level domain (TLD) servers.
  4. TLD DNS server. The root DNS servers respond to the resolver’s query by providing the IP address of the TLD DNS server responsible for the specific TLD of the requested domain. For example, if the requested domain is “example.com,” the TLD DNS server for the “.com” TLD is identified.
  5. Authoritative DNS server. The DNS resolver contacts the TLD DNS server to obtain the IP address of the authoritative DNS server responsible for the domain “example.com.” The authoritative DNS server is where the specific DNS records, including CNAME records, for the domain are maintained. After that, the DNS resolver caches the obtained information, which helps in faster responses for subsequent queries and reduces the load on DNS infrastructure.

To summarize, DNS manages CNAME records by using resolvers to systematically query authoritative DNS servers, following any CNAME records encountered along the way, until the ultimate destination is reached. Caching improves efficiency and reduces the need for repeated queries.

Best Practices of Working with CNAME Records

Creating CNAME records requires thoughtful consideration to ensure a seamless experience and avoid potential issues—such as incorrect configurations of CNAME records—that can lead to downtime in online services. By following these five best practices, you can effectively manage your CNAME records and optimize your domain name setup.

#1 Identify The Purpose Of Your CNAME Record

Clearly define the purpose of the CNAME record; is it for domain redirection, subdomain setup, or integration with third-party services?

#2 Verify Record Compatibility

Once you know the purpose of the CNAME record you’re trying to set up, ensure that the CNAME records you create are compatible with your specific use case and the services you plan to integrate. For instance, if you’re integrating a CDN to your website, you should contact the CDN provider to obtain the correct CNAME value that you need in order to add to your CNAME record. It’s important to note that different services may have their own requirements and limitations when it comes to CNAME records, so it is highly recommended also to contact the support team of your DNS hosting provider for assistance.

#3 TTL Management

Time to live (TTL) is a value that indicates the lifespan of data in a network before it is removed. For effective TTL management, set an appropriate TTL value for the CNAME record. Consider the frequency of changes and the desired responsiveness. Lower TTL values result in quicker updates but may increase the DNS query load.

Example: When setting up a CDN, you need to enter the correct value provided by your CDN provider. This value determines how long DNS resolvers should keep the DNS records cached. Typically, the recommended TTL value for this is around 3600 seconds (1 hour,) which helps to balance caching efficiency and responsiveness.

#4 Avoid CNAME Chains

Minimizing the use of multiple CNAME records in a chain is recommended to avoid unnecessary latency and potential points of failure. Each additional CNAME lookup introduces delays in the DNS resolution process and increases the likelihood of encountering issues.

Example: Here is a CNAME chain consisting of three links. The chain begins with the subdomain “sales.example.com,” which directs to “marketing.example.com.” The “marketing.example.com” subdomain, in turn, directs to “promotions.example.com,” and finally, the “promotions.example.com” subdomain directs to “offers.example.com.”

TypeHostnameValue
CNAMEsales.example.commarketing.example.com
CNAMEmarketing.example.compromotions.example.com
CNAMEpromotions.example.comoffers.example.com

This usually happens when the website owner creates a new web page and also creates a new subdomain, then wants to redirect users to the new site. The process repeats itself again, and the website owner decides to create another one. As a result, it could cause excessive redirections that can lead to delays for the users.

#5 Perform Record Testing

To ensure that your CNAME record is working correctly, test its configuration and confirm it’s functioning as expected. You can do this by verifying that the record resolves accurately and redirects traffic to the intended destination. For example, after setting up a CNAME record, perform DNS lookups or utilize online DNS tools to verify the record’s accuracy.

What Are the Limitations of CNAME Records?

After understanding the different ways to use CNAME records on your website, it’s important to keep in mind the restrictions that come along with them. This next section will explore these limitations and their potential impact.

  • Limited direct use for the root domain. A significant drawback of CNAME records is that they cannot be utilized for the root domain (example.com.) Only subdomains (e.g., mail.example.com) can use CNAME records.
  • DNS resolution time may take longer. Due to the additional step in DNS lookup, it can lead to a slower website loading experience for users, especially for the first time they visit the website.
  • It can’t coexist with other DNS records. DNS rules prevent you from having both CNAME and other record types for the same subdomain. For instance, you can’t set up a CNAME for “mail.example.com” and also create an MX record with the same name.

For the latter situation, Gcore DNS provides the CNAME Flattening feature. But what exactly is CNAME flattening and how does it operate? Let’s delve into the details in the next section.

CNAME Flattening with Gcore

Gcore’s DNS service offers CNAME flattening to all our clients by default, regardless of their plan. CNAME flattening feature enables the use of CNAME records at the root domain. It accomplishes this by providing the IP address of the host during the lookup process, ensuring adherence to the DNS specifications.

TypeNameContentTTL
CNAMEblog.example.comexample.com3600 seconds
Table 1. Traditional CNAME record

The CNAME flattening feature helps avoid possible issues and makes the resolution process faster. Here’s an example:

TypeNameContentTTL
CNAMEexample.comexample.sitebuilder.com3600 seconds
Table 2. CNAME record with CNAME flattening

Our service also functions as an internal DNS cache that allows for CNAME flattening. This means that it resolves the chain of CNAME records and provides the IP address of the host, which can speed up DNS lookups and enhance your application’s performance.

How to Implement CNAME Flattening

To implement CNAME flattening, replace the previous A record for the domain root with the flattened CNAME record. For instance, suppose you have a domain, “example.com,” and you intend to use a CNAME record for the root domain to direct it to a third-party service that hosts your website, like “website-buildersite.com.”

Here’s how this might look without CNAME flattening:

TypeNameValue
CNAMEexample.comwebsite-buildersite.com

The CNAME record above doesn’t follow DNS standards, so it won’t function as intended. This is because CNAME records are not permitted at the root level. Now, let’s see how to use CNAME flattening to make it work properly.

First, remove A record before CNAME flattening is applied:

TypeNameContentTTL
Aexample.com192.168.0.13600 seconds

It is important to remove any existing A record and to ensure that there is only one record in the CNAME record set for the root domain. If there are multiple records in this set, CNAME flattening will not occur.

Next, create the CNAME record for the root domain “example.com” that points to the desired domain name:

TypeNameValueTTL
CNAMEexample.comwebsite-buildersite.com3600 seconds

That’s it, you’ve successfully implemented CNAME flattening!

Aside from CNAME flattening, Gcore DNS offers superior performance for managing your DNS. Our dedication to achieving minimal response times globally ensures that your applications load incredibly fast and without any issues.

Conclusion

CNAME records are crucial for delivering online services and are commonly used for subdomain redirection, CDN integration, email services, and analytics. However, using CNAME records at the root domain presents challenges. To overcome this, CNAME flattening can be employed, transforming CNAME records into A records for compatibility.

At Gcore, we offer CNAME flattening as a free feature in our DNS hosting service, allowing you to manage DNS records efficiently and ensure seamless operations for users. Whether you’re new to DNS or an experienced webmaster, our DNS hosting makes CNAME and other DNS record management easy and hassle-free. Reach out to our experts and we will be delighted to help you get started.

Subscribe to a useful newsletter

Favorable offers and important news once a month. No spam.