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:
Hostname | Record Type | Value | TTL |
www.example.com | CNAME | @ (example.com) | 1800 seconds |
blog.example.com | CNAME | blogalias.com | 3600 seconds |
mail.example.com | CNAME | domainverify.googlehosted.com | 3600 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:
Type | Hostname | Value |
CNAME | old-johnapparel.com | new-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:
Type | Hostname | Value |
CNAME | support.abc-corp.com | support-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:
Type | Hostname | Value |
CNAME | shoesandmore.com | cdn-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:
Type | Hostname | Value |
CNAME | mail.handmadecrafts-treasures.com | mail.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:
Type | Hostname | Value |
CNAME | www.xyz-goods-onlinestore.com | analytics.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.
Here are the steps used by DNS to manage and resolve CNAME records:
- User sends a request. The process begins when a user sends a request, such as entering a websiteâs URL into their web browser.
- 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.
- 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.
- 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.
- 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.â
Type | Hostname | Value |
CNAME | sales.example.com | marketing.example.com |
CNAME | marketing.example.com | promotions.example.com |
CNAME | promotions.example.com | offers.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.
Type | Name | Content | TTL |
CNAME | blog.example.com | example.com | 3600 seconds |
The CNAME flattening feature helps avoid possible issues and makes the resolution process faster. Hereâs an example:
Type | Name | Content | TTL |
CNAME | example.com | example.sitebuilder.com | 3600 seconds |
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:
Type | Name | Value |
CNAME | example.com | website-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:
Type | Name | Content | TTL |
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:
Type | Name | Value | TTL |
CNAME | example.com | website-buildersite.com | 3600 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.