What is a CNAME record and how does it work?

What is a CNAME record and how does it work?

If you have a website, you might have heard about something called a CNAME record. But what is it, and how does it work? Let's break it down.

What is a CNAME record?

A CNAME record is a type of DNS record that allows you to associate one domain name with another. DNS stands for Domain Name System, and it's what helps the internet connect users with websites using easy-to-remember domain names instead of IP addresses.

In a way, a CNAME record acts like a shortcut or an alias for a domain name. It's similar to the way you might create a shortcut on your computer desktop to quickly access a frequently used program or file.

For example, let's say you have a website that you've hosted on a server, and the domain name associated with it is "example.com". However, you also want to create a subdomain called "blog.example.com" and have it point to a different server or hosting provider. You can create a CNAME record that associates "blog.example.com" with the IP address or domain name of the new server, and anyone who types in "blog.example.com" in their browser will be redirected to the new server.

How does a CNAME record work?

When you create a CNAME record, you're essentially telling the DNS resolver to associate a domain name with another domain name. The CNAME record maps one domain name to another, which means that when someone types in the first domain name, their device or computer will look up the IP address associated with the second domain name and then connect to the server hosting that website.

For instance, let's say you have a website hosted on a server with the IP address 192.168.0.1, and the domain name associated with it is "example.com". You also have a subdomain called "blog.example.com" that you want to redirect to a different server with the IP address 192.168.0.2. You can create a CNAME record that associates "blog.example.com" with the domain name of the new server, such as "newserver.com".

When someone types in "blog.example.com" in their browser, their device or computer will first look up the IP address associated with "blog.example.com". Since "blog.example.com" is a CNAME record, it will then look up the IP address associated with "newserver.com" and connect to the server with that IP address. This server will then send back the webpage that the user requested.

Why use a CNAME record?

There are several reasons why you might use a CNAME record:

  • Redirecting subdomains: As we discussed earlier, one of the most common reasons to use a CNAME record is to redirect a subdomain to a different server or hosting provider. For instance, you might have a blog that you've hosted on a different server from your main website, and you want to create a subdomain for it, such as "blog.example.com". You can create a CNAME record that associates "blog.example.com" with the domain name or IP address of the server where your blog is hosted.
  • Creating custom URLs: Another reason to use a CNAME record is to create custom URLs for your website. For example, you might have a long URL for a specific page on your website, such as "example.com/page-1234". You can create a CNAME record that associates a shorter, more memorable URL with that page, such as "info.example.com", and anyone who types in "info.example.com" in their browser will be redirected to "example.com/page-1234".
  • Load balancing: You can also use CNAME records for load balancing, which is the practice of distributing traffic across multiple servers to improve performance and reliability. For instance, if you have a high-traffic website, you might have multiple servers hosting the same content. You can create a CNAME record that associates your domain name with multiple IP addresses or domain names, and the DNS resolver will distribute the traffic across these servers based on various factors, such as availability, response time, or location.
  • Migrating websites: Finally, you can use CNAME records to migrate your website to a new server or hosting provider without losing traffic or search engine rankings. When you migrate your website, you need to change the IP address or domain name associated with your domain name. However, if you have a CNAME record that associates your domain name with the new server or hosting provider, you can change the CNAME record instead, and anyone who types in your domain name will be redirected to the new server or hosting provider.

The impact of CNAME records on website performance

CNAME records can impact website performance because they add an extra step in the DNS lookup process. When a user types in a domain name with a CNAME record, the DNS server has to look up the CNAME record and then look up the domain name specified in the record. This can cause a delay in website loading times, especially if there are multiple CNAME records involved.

The delay in website loading times can be further exacerbated if the DNS server is located far from the user. The longer the distance between the user and the DNS server, the longer the DNS lookup time will be. This is because the DNS query has to travel across multiple networks to reach the DNS server, and each network has its own latency and potential for congestion.

Website owners can mitigate the impact of CNAME records on website performance by minimizing the number of CNAME records used on their website. They can also use a DNS provider that has multiple DNS servers located in different regions to reduce the distance between the user and the DNS server. Additionally, website owners can use a CDN (Content Delivery Network) to cache static content and reduce the number of DNS lookups required for each page load.

The impact of CNAME records on SEO

CNAME records can also impact SEO (Search Engine Optimization) because they can cause duplicate content issues. If a website has multiple domain names that map to the same content through CNAME records, search engines may consider this as duplicate content and penalize the website for it.

For example, if a website has the domain names www.mywebsite.com and blog.mywebsite.com, and blog.mywebsite.com maps to www.mywebsite.com through a CNAME record, search engines may see this as duplicate content and penalize the website for it. To avoid this issue, website owners should use 301 redirects instead of CNAME records to redirect users to a different domain name or use canonical tags to specify the preferred domain name for search engines.

How to transfer CNAME records between DNS providers

Transferring CNAME records between DNS providers is usually a straightforward process. Here are the general steps:

  • Log in to your current DNS provider's control panel.
  • Find the CNAME record you want to transfer.
  • Copy the record's details, including the domain name it maps to and the value it maps to.
  • Log in to your new DNS provider's control panel.
  • Create a new CNAME record with the same details as the old record.
  • Wait for the DNS changes to propagate (this can take anywhere from a few minutes to a few hours).
  • Test your website to make sure it's still accessible at the same domain name.

It's important to note that the process of transferring CNAME records may differ slightly depending on your DNS provider. Some providers may have different control panel layouts or may use different terminology for their DNS settings.

Additionally, it's important to make sure that you have all of your CNAME records transferred to your new DNS provider. If you have multiple CNAME records, make sure you transfer them all to avoid any potential issues.

If you are not comfortable transferring your CNAME records yourself, many DNS providers offer migration services that can help you transfer your records for you. These services can be especially helpful if you have a large number of records or if you are not familiar with the technical details of DNS.

Best Practices for Transferring CNAME Records

When transferring CNAME records between DNS providers, there are some best practices that you should follow to ensure a smooth transfer:

Backup your current DNS records

Before making any changes to your DNS settings, it's a good idea to create a backup of your current records. This will allow you to restore your settings if anything goes wrong during the transfer process. Most DNS providers have an option to export your DNS records as a file, which you can then save as a backup.

Reduce your DNS TTL

TTL (Time to Live) is the amount of time that DNS servers will cache your DNS records before checking for updated information. By reducing your TTL to a low value (such as 300 seconds), you can help ensure that any changes you make to your DNS records propagate quickly. This will help minimize downtime for your website during the transfer process.

Test your website before and after the transfer

Before you transfer your CNAME records, it's a good idea to test your website to make sure it's working properly. This will help you identify any issues that may exist before you make any changes. After the transfer, you should test your website again to ensure that everything is working as expected.

Don't make changes during the transfer process

While your DNS records are propagating, it's important not to make any changes to your DNS settings. This can cause inconsistencies and make it more difficult to troubleshoot any issues that may arise.

Monitor your DNS settings after the transfer

After the transfer is complete, it's a good idea to monitor your DNS settings for a few days to ensure that everything is working properly. This will help you identify any issues that may arise and allow you to quickly address them.

Advanced techniques for using CNAME records

Here are some advanced techniques for using CNAME records:

Load balancing

Load balancing is a technique that distributes traffic across multiple servers, which helps to improve website performance and reduce downtime. By using CNAME records to distribute traffic across multiple servers, you can ensure that your website remains up and running even if one server goes down.

When using load balancing with CNAME records, you simply create multiple CNAME records that point to different servers. When a user requests your website, their request is routed to one of the servers specified in the CNAME record. This helps to distribute the load across multiple servers, which helps to improve website performance and reduce downtime.

Load balancing is especially useful for websites that receive a large amount of traffic. By distributing the load across multiple servers, you can ensure that your website remains fast and responsive, even during times of high traffic.

Subdomain mapping

You can use CNAME records to map subdomains to different servers or services. For example, you can map blog.example.com to a blogging service like WordPress or Medium, while keeping the rest of your website hosted on a different server. This can help you use specialized services while still keeping your website cohesive.

Subdomain mapping is useful when you want to use a different server or service for a specific part of your website. For example, you might use a specialized service for your blog, or you might want to host your email on a different server. By using CNAME records to map specific subdomains to different servers or services, you can achieve this without affecting the rest of your website.

To map a subdomain to a different server or service using a CNAME record, simply create a new CNAME record that points to the server or service you want to use. For example, to map blog.example.com to WordPress, you would create a CNAME record with the name "blog" and the value "wordpress.com".

Domain aliasing

Domain aliasing is another technique that can be used with CNAME records. With domain aliasing, you can use multiple domain names to point to the same website content. This is useful if you have multiple domain names that you want to use for marketing or branding purposes, or if you want to redirect traffic from an old domain name to a new one.

To create a domain alias using CNAME records, simply create a new CNAME record with the name of the domain you want to alias and the value of the canonical domain name. For example, to alias www.example.net to www.example.com, you would create a CNAME record with the name "www.example.net" and the value "www.example.com".

Domain aliasing can be especially useful for businesses that have multiple brands or products. By using different domain names for each brand or product, you can create a cohesive marketing strategy while still using the same website content.

Conclusion

In summary, a CNAME record is a type of DNS record that allows you to associate one domain name with another. It acts like a shortcut or an alias for a domain name and allows you to redirect subdomains, create custom URLs, load balance traffic, and migrate websites. By understanding how CNAME records work, you can make the most of your domain name and ensure that your website is accessible and reliable for your users.

Ready to take the next step?

Stop reading, start building.

Experience the speed of MarbleHost for 30 days, completely on us. Get full access to NVMe storage and 24/7 support. No credit card required, no strings attached.

Activation takes less than 2 minutes.
Petr Sejba
Petr Sejba Founder of MarbleHost & Digital Strategist

Petr has been active in online marketing since 2000. He is a performance marketer and the founder of MarbleHost (started in 2005). Petr looks at hosting differently than most: he believes it is not just about servers, but about business results. He spends his time managing MarbleHost and running his advertising agency in Spain. His goal is simple: to make sure your technology helps your business grow.

More articles by Petr Sejba →