Can a domain name have multiple CNAME records?

Share your love

CNAME DNS records are essential when you want to avoid redundancy when configuring your DNS record types. Commonly, you may find a CNAME record will only be required once in your DNS settings. Other times, you may need to add more than one CNAME record for your domain’s DNS records configuration.

A domain name can have multiple CNAME records in its DNS configuration. More than one CNAME record may be required when setting up your website’s CDN (Content Delivery Network) or creating alias names that fall under your primary domain. Thus, avoid redundancy by specifying the IP address for each alias name. Examples of alias domains are ones used in a CDN configuration and ftp, mail, www, e.t.c. Thus, you can set up the www version of your website using CNAME records as an example.

CNAME records are critical in enabling efficient HTTP request processing in a CDN (Content Delivery Network). Besides, CNAME records are used when creating aliases for your subdomains. In detail, let’s see how CNAME records are used in a DNS setup.

In this setup, we are going to be using Ezoic. Ezoic is a service that provides you with a ton of features ranging from caching, CDN, website optimization, site monetization through ads, content creation tools, e.t.c. This tutorial will focus on the CDN part as an example. If you want to check out the advantages of using Ezoic, follow this link.

How CNAME records are used in primary domain and subdomain configuration

CNAME records point to your primary domain name and other subdomains you have created for your website. For a domain name or subdomain to resolve whenever a request is made to it (a user accessing your website through your website URL), it must have an IP address to go to.

For this reason, you would require an A (address) record for your primary domain and subdomains. Primarily, a domain name is available in the www and non-www versions. Besides, you can have more than one subdomain present for your domain.

If you have noticed, adding an A record or quad A record (AAAA) for each URL version of your domain name and subdomains can be tedious. You must prefer another alternative solution.

CNAME records help in such a setup that requires the addition of multiple URL versions and subdomains for your domain name. To achieve this, you should only create an A or AAAA record for your primary domain and use CNAME to point to the primary domain for your www version of your URL and subdomains.

Here is a step-by-step on how to set up A record for your primary domain and use CNAME for your www URL version and subdomains.

How to create a CNAME record for the www version of your domain

Action 1: Create an A or AAAA record for your root domain

Login to your domain registrar and access the DNS management settings. If you have added your website to Cloudflare, you will need to log in to your account, select the domain name, and access the DNS tab.

Once you have accessed the DNS management or DNS tab, you can add an A or AAAA record for your primary domain by following these steps:

Step 1: Press add record button
Adding a DNS record in CloudFlare
Step 2: Select the DNS record type as A or AAAA
Step 3: Enter the name of the A or AAAA record as @

Use @ to point to your root domain. Thus, your root domain (yourdomainname.com) will always resolve to the IPV4 or IPV6 you are to provide.

Step 4: Enter A or AAAA record value/content

For the value for your A record, enter the IPV4 address for your server. If you have an IPV6 address, ensure you have selected the record type as AAAA and paste your IPV6 address here. Your hosting provider will provide you with the IPV4 or IPV6 address. Usually, you need to log in to your hosting account to find the IP address of your server.

Step 5: Specify the TTL value as auto or 3600 and save your DNS record

Action 2: Create a CNAME record for the www version of your domain name

Access the DNS management or DNS tab. Add a CNAME record for your www domain name version by following these steps:

Step 1: Press add record button
Adding a DNS record in CloudFlare
Step 2: Select the DNS record type as CNAME
Step 3: Enter the name of the CNAME record as www

Use www to point to your root domain and use the same IP address. Thus, your www URL version (www.yourdomainname.com) will always resolve to the IPV4 or IPV6 specified in the root domain. Therefore, you avoid the redundancy of creating multiple A or AAAA records for your www and non-www version of your domain name.

Step 4: Enter CNAME record value/content as your root domain (yourdomainname.com)

For the value of your CNAME record, enter the root domain that has the A or AAAA record pointing to the IP address of your server.

Do not enter the IP address for a CNAME record type. CNAME records must not be used to point to an actual IP address. Thus, always use the root domain name as the value of your CNAME records.

Step 5: Specify the TTL value as auto or 3600 and save your DNS record

How to create CNAME records for your subdomains

Step 1: Create a CNAME record for your subdomain

Login to your domain registrar and access the DNS management settings. If you have added your website to Cloudflare, you must log in to your account, select the domain name, and access the DNS tab.

Once you have accessed the DNS management or DNS tab, you can add a CNAME record for your subdomain by following these steps:

Step 1: Press add record button
Adding a DNS record in CloudFlare
Step 2: Select the DNS record type as CNAME
Adding a CNAME DNS record
Step 3: Enter the name of the CNAME as the name of your subdomain

Suppose your subdomain is ‘portfolio’; use ‘portfolio’ as the name of your CNAME record. Thus, you will end up having portolfio.yourdomainname.com. However, do not enter the name of your CNAME record as portfolio.yourdomainname.com.

Step 4: Enter CNAME record value/content as the root domain

For the value of your CNAME record, enter the root domain that has the A or AAAA record pointing to the IP address of your server.

As we said earlier, you should not specify an IP address as the value for a CNAME record type.

Step 5: Specify the TTL value as auto and save your DNS record

That’s it, you should have your subdomain live, and you can assess the new URL, which should resolve to the same IP address as your root domain.

Following the same steps, you can add other subdomains you may have created from your root domain. In a common setup, you should add these subdomains in your DNS settings:

  1. autodiscover
  2. ftp
  3. mail
  4. autoconfig

Role of CNAME records in a CDN setup (How CDN works)

Cname records can also be used in CDN setups where the local DNS server will always redirect to the CDN near the users using CNAME records. According to the user’s geographical location, the CDN should be able to provide the user with the IP address of a node that has a faster response.

CDN works by caching a version of your website to locations near your users. Thus, a user in Africa should be able to access a cached version of your website using a CDN server located in, let’s say, South Africa. Thus, the user will be able to access the website much faster.

If your website is not cached in that location, the CDN node (in South Africa, for example) will retrieve the original version of your website from the original server and serve it to the user.

To understand how a CNAME is used in a CDN setup, here is an example using Ezoic CDN.

How HTTP requests are made in a CDN setup (Step by step process)

Trigger 1: A user types in your domain URL in the browser and requests local DNS to resolve the IP address

A user makes a request by accessing the URL of your website, www.yourdomainname.com. The browser requests the local DNS to resolve the domain URL to the server containing the resources.

Trigger 2: The local DNS requests the Authoritative DNS to resolve the CNAME record

The local DNS makes a request to the authoritative DNS to resolve the CNAME record of your domain name. The authoritative DNS returns the CNAME record, which points to a CDN URL. In this example, it returns www.yourdomainname.com.yourcdn.com, which is a CDN URL. Or, cd1.yourdomainname.com.

Trigger 3: The local DNS requests the CDN system for a node IP

The local CDN makes a request to resolve the IP address of the CDN version of your site by using the CNAME record provided. In this case, cdn-1.yourdomainname.com. As an example, try cdn-1.ngangasn.com.

The local DNS asks the CDN scheduling system for the fastest server that will respond to the request. Thus, it returns the optimal node. For our example, it will return the node closest to the user, South Africa. The node has an IP address that is returned to the user that made the request.

Trigger 4: The user request site content using the provided IP address

As the local DNS resolves the domain name to an IP address, the browser requests the CDN node server to access the content/resources of your website. Because there is a cached version, the user accesses the content from the closest CDN server node. Thus, the site loads faster.

If the website is not cached in the nearest server, the CDN node makes a request to the origin server to provide the resources and content of your website.

As you have seen, the CNAME record has been used in a CDN record to return the CDN node that is closest to the user making a request. As major CDNs such as Ezoic or Cloudflare use servers in different locations, you will have multiple CNAME records pointing to different CDN nodes. Thus, the CDN intelligent scheduling system can schedule the optimal node closest to the user.

This screenshot shows that a typical Ezoic CDN setup uses more than one CDN node configured using CNAME records.

From the Ezoic CDN example and an outline of how CDN works, you can see that you can have more than one CNAME record configured for your domain. Thus, these CDN nodes will resolve to the following domain names for each CNAME that the Ezoic CDN scheduling system will choose.

  1. cdn.pxys.ezoic.net
  2. cdn-1.pxys.ezoic.net
  3. cdn-2.pxys.ezoic.net
  4. cdn-3.pxys.ezoic.net
  5. cdn-4.pxys.ezoic.net
  6. cdn-5.pxys.ezoic.net
  7. cdn-6.pxys.ezoic.net
  8. cdn-7.pxys.ezoic.net

Each CNAME record will resolve to an actual IP address of the server node containing the cached version of your website.

As the same case for the domain aliases, CNAME records should not be duplicated in a CDN configuration. Besides, the CNAME record points to actual CDN node domain names rather than IP addresses.

Conclusion

A domain name can have more than CNAME records in its DNS records configuration. The need to add multiple CNAME records arises from adding several subdomains, a www version of your website, and connecting to a CDN service such as Ezoic. The end goal is to avoid redundancy.

You may check out this other article I have written to learn about TXT records.

Struggling to find affordable hosting for your Django web application?

This hosting service offers a cost-effective solution that is tailored for

  1. VPS hosting for Django
  2. Shared hosting for Django

Allowing you to:

🚀 Supercharge Your Ideas: Worried about investing too much upfront? Our affordable shared hosting lets you test and validate your innovative concepts created using Python Django without draining your budget.

🎯 Lure and Impress Clients With an Already Deployed Django Project: You just need one hosting plan to host unlimited Django websites.

⚙️ Hassle-Free Setup: With the user-friendly interface, you’ll have your Django project up and running in minutes with this Django-ready optimized host. Besides, I have written an article for you to use to deploy your Django app, here.

Act now while there is a huge discount on their hosting plans. Use the link below

Secure Your Hosting Server Now!

Share your love
Badi
Badi

Badi here, creator of ngangasn.com— A website dedicated to providing helpful information and how-to's of web development and hosting. Inspired by a fascination to write the most efficient code to make a computer laugh, & humans, Steve has a passion for organizing characters to create code and informative content.
What makes me happy?
Well, nothing like the feeling of finally figuring out that one pesky bug that's been driving me crazy.

One comment

Leave a Reply

Your email address will not be published. Required fields are marked *