What are CNAME Records and How Do They Work?

A CNAME record is a type of DNS record that maps a domain name to another domain name.

It stands for Canonical Name because it creates an alias that lets directs you to the given domain name.

When you enter a website address in your browser, the owner of that domain could use a CNAME record to route you to its associated domain without having to update the URL in your browser.

For example, if www.testsuite.io used a CNAME record to point to testsuite.io, then if your browser requested www.testsuite.io it would be redirected to testsuite.io and give you the response from hitting testuite.io. CNAMEs don't actually redirect you though, so the URL in your browser wouldn't change. They merely route the outbound request to a different domain and return the response from hitting that server.

CNAME Records vs Other Options

A CNAME record is similar to an A record in that both types of records point you to a different source.

AWS Made Easy
AWS Made Easy
How to learn AWS quickly and easily.
AWS Made Easy
LEARN MORE

The difference is CNAMEs point to another domain while A records point to a specific IP.

They are usually used together in practice since a CNAME will point to another domain and that domain will have an A record giving us the IP address of the server we are trying to reach.

CNAME Restrictions

There are a few rules that come with CNAME records:

  • They can't point to an IP address
  • They can't be placed on apex domains
  • NS and MX records can't point to a CNAME
  • There are problems with using CNAME domains for email
  • It's not a good practice to point a CNAME record to another CNAME records

Wrapping Up

The CNAME record is also similar to the ALIAS record because both map a hostname to another hostname.

While CNAMEs don't allow other DNS records on the same hostname, ALIAS records do. Making it possible to use ALIAS on apex domains. You can't do that with a CNAME.

Featured
Level up faster
Hey, I'm Nick Dill.

I help people become better software developers with daily tips, tricks, and advice.