What Is a DNS CNAME Record?

Within the domain name system (DNS), various records provide specific instructions on how to route users to the desired online resources. CNAME is one of these records; a CNAME record acts as a pointer that redirects queries for a particular domain name to another domain name. In this article, learn what CNAME records are, how they work, and how to implement them.

What is a CNAME?

A CNAME record, short for Canonical Name record, is a type of DNS record that maps an alias name to a true or canonical domain name. This DNS entry is commonly used when you want to associate a new subdomain with an existing domain's DNS records.

It essentially functions like a nickname within the DNS. When a user tries to access the alias domain, the CNAME record redirects the DNS lookup process to the canonical domain. This redirection is seamless for the user and allows for more flexible domain management.

For example, you might use a Canonical Name record to point www.example.com to the domain name example.com.

When configuring a CNAME record, it's essential to understand its structure. The primary components of a Canonical Name record include the alias name, the TTL (Time to Live), and the canonical hostname it points to. Here's a simple breakdown:

  • Alias Name: The subdomain or prefix you create a CNAME for (e.g., www).
  • TTL: The time in seconds that DNS resolvers will cache the record.
  • Canonical Hostname: The domain name the alias points to (e.g., example.com).

It's important to note that a CNAME record cannot coexist with any other record type for the same alias. In other words, if you have a Canonical Name record for www.example.com, you cannot have an A record for www.example.com at the same time.

What is the purpose of CNAME records?

A CNAME record is intended to simplify domain management and facilitate website maintenance. It provides a means to associate multiple domain names with a single resource, streamlining the process of updating and migrating web content.

Additionally, these records enable the implementation of domain aliases. Users can access websites through alternative domain names while maintaining a single point of origin.

CNAME records map domain names on the Internet.

How Canonical Name records work

Canonical Names work by creating aliases for domain names, allowing multiple domain names to resolve to the same IP address. When a subdomain like "www" is set as a CNAME alias for the root domain, for example, "www.samplesite.webname.com" pointing to "webname.com," a CNAME record is created.

When a DNS server looks up a domain like "blog.samplesite.com," it also checks the record for "webname.com" due to the alias. This restarts the query using the canonical name, "webname.com," and retrieves its IP address through its A record. Here, "samplesite.webname.com" becomes synonymous with "webname.com."

If the host's IP address changes, only the DNS A record for the root domain, "webname.com," needs updating. Any change automatically affects all Canonical Name records, including "blog.webname.com.”

Why do you need a CNAME record?

CNAME records offer several benefits, including:

  • Simplified domain management. The records streamline domain management by eliminating the need for duplicate A records for subdomains pointing to the same server. They directly reduce the workload of managing multiple other DNS record types.
  • Security considerations. Canonical Name records themselves don't directly enhance security. However, they can be used with security certificates issued for the canonical domain to provide a secure connection for the alias domain as well.
  • Improved flexibility. This type simplifies switching hosting providers for websites that rely on them. If your subdomains use CNAME records pointing to your old provider's domain, updating the record to point to your new provider's domain automatically redirects traffic. This eliminates the need to modify individual A records for each subdomain.

What are the limitations of a CNAME record?

Canonical Name records do have limitations. Though they help redirect and improve web functionality, consider the areas where they may fall short.

  • Limited functionality. CNAME records offer a redirection function, not a direct mapping function. The records only point to other domain names; they don't point to an to IP directly.
  • Performance impact. Excessive chaining of Canonical Name records (where one record points to another) can introduce slight delays in DNS resolution. It can create a cascade effect that slows down DNS lookup times.
  • SEO implications. While search engines generally recognize Canonical Name records and credit backlinks to the canonical domain, some argue that a strong subdomain presence can positively impact SEO.

CNAME vs. other DNS records

CNAME records are unique in the DNS ecosystem, serving a specific role that differs from other types of records. A Canonical Name record creates an alias for a domain so that multiple service endpoints reference it without needing to update each one in the event of a change.

In contrast, A records map a domain name directly to an IP address. It serves as the cornerstone of DNS. MX records are specialized for directing email to mail servers, with priorities indicating the order of preference. PTR records are responsible for reverse DNS lookups.

While CNAME records can point to other Canonical Name records, ultimately, the chain must resolve to a valid A or AAAA record. This is because the records do not directly associate with IP addresses but rely on the target domain's resolution.

How Canonical Name records differ from redirects

CNAME records and redirects might seem the same, but they work differently. While a CNAME points to another domain, it doesn't automatically trigger a redirection of web traffic.

To perform an HTTP redirect, you need to configure the server handling the HTTP requests to send the appropriate redirect response. Setting up a Canonical Name alone will not redirect web traffic; you need to configure the server separately to do so.

In essence, a Canonical Name record deals with DNS resolution. An HTTP redirect, on the other hand, involves server-side actions to route web traffic.

How to set up CNAME records

Adding a Canonical Name record to your domain's DNS settings is straightforward. Follow these general steps to complete the process.

  1. Access the DNS settings for your domain within your hosting provider's dashboard.
  2. Locate the section for Custom Records or similar.
  3. Choose Add record and select CNAME from the Type dropdown menu.
  4. In the Host field, specify the subdomain or host record (e.g., 'www').
  5. Enter the target domain in the Data or Points to field.
  6. Confirm your entries and click Save to apply the changes.

It's important to ensure the target domain is a fully qualified domain name, not an IP address. DNS propagation, where the changes take effect across the Internet, can take anywhere from a few hours to 48 hours.

Best practices for implementing Canonical Name records

Properly implementing CNAME records is essential for a website's functionality. Make sure to allow for these considerations in order to use CNAME records effectively.

First, ensure that CNAME records are clearly defined and point to the correct canonical domain names. Avoid long chains of CNAME records for optimal performance, and if multiple CNAME records are necessary, consider restructuring your DNS configuration.

You also must understand the service requirements; when integrating cloud services, carefully review their documentation to understand specific CNAME record requirements.

Keep in mind that DNS changes, including CNAME record updates, can take some time to propagate across the Internet. When planning updates, account for that time.

Practical applications of CNAME records

Some common scenarios where CNAME records are employed include:

  • Website redirection. People often use the Canonical Name to send visitors from numerous websites owned by a single entity to the main website.
  • Content delivery networks (CDNs). CDNs leverage Canonical Name records to distribute web content across geographically dispersed servers. By utilizing CNAME aliases, CDNs can deliver content from the server closest to the user.
  • Subdomain mapping. Canonical Name records enable the mapping of subdomains to specific services. For example, a subdomain such as "blog.example.com" could be mapped to a separate hosting platform using a CNAME record.
  • Email services. The CNAME record is meaningful when configuring email services, particularly for domain verification and authentication purposes. Domain owners can create CNAME records for DKIM and SPF to mitigate the risk of email spoofing.
  • Cloud services integration. Many cloud platforms like Google Workspace or Microsoft 365 require CNAME record creation for services like cloud storage. The CNAME record points the subdomain to the provider's domain, enabling seamless service integration.

Frequently asked questions

How does a CNAME record differ from an A record?

A Canonical Name record points a subdomain to another domain name, whereas an A record points a domain to an IP address. Canonical Name records must always point to another domain name and never directly to an IP address.

Can a CNAME record point to another CNAME record?

Yes, it’s possible. However, the final record in the chain must resolve to a hostname with a valid IP address, which is usually provided by an A record.

What is CNAME flattening, and why is it used?

CNAME flattening is a process that allows the apex domain (the root domain) to be pointed to using a Canonical Name record. This is useful for performance because it allows DNS to update smoothly if the site is migrated to another server.

What is a CNAME lookup?

A Canonical Name record lookup is a query to DNS servers that requests the return of Canonical Name records for a domain.