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.
CNAME, short for canonical name, is a type of DNS (Domain Name System) record. A CNAME record is used in two contexts:
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.
Here is a table with an example of a CNAME record:
|www.example.com||CNAME||@ (example.com)||1800 seconds|
Let’s examine each of these components and their functions in detail.
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.
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:
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:
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:
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:
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:
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:
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.
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.
Clearly define the purpose of the CNAME record; is it for domain redirection, subdomain setup, or integration with third-party services?
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.
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.
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.”
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.
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.
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.
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.
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.
The CNAME flattening feature helps avoid possible issues and makes the resolution process faster. Here’s an example:
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.
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:
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:
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:
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.
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.