Skip to content
dnscheck.app

Glossary

CNAME Record: Definition, Example and How It Works

What is a CNAME record?

A CNAME (canonical name) record marks a name as an alias, another name for the same place, and gives the canonical name, the real name it stands for. An alias has only one canonical name, but many aliases can point to one host.

shop.example.com.    3600 IN CNAME hosting.example.net.
hosting.example.net. 3600 IN A     192.0.2.10

The fields are name (the alias), TTL, class, type and target. The TTL is the number of seconds other DNS servers may cache the record.

How a CNAME works and when to use it instead of an A record

A resolver is the server that looks up answers for users. When it asks for an A record at an alias, the response holds the CNAME and the target's A record. A CNAME-type query returns only the CNAME.

Use a CNAME when a name should follow another name, such as www pointing to a group of servers. Use an A record when the name needs its own address. A CNAME cannot point to an IP address. Its target is the full domain name of the host.

CNAME A
Role Alias to another name Address record at the name
Other records at the same name Should be none Allowed
Valid as an MX or NS value No Yes, if the name has address records

CNAME rules and common mistakes

  • No other data should be present at a CNAME name. A name that must also carry MX or TXT records cannot be an alias. This is why a CNAME rarely fits at the root of a domain. The standard says "should", and DNS hosts may enforce it differently.
  • An NS value or MX value must not be an alias.
  • Pointing at the canonical name directly avoids extra indirections.
  • Long chains are inefficient but not an error. Loops and aliases to non-existent names are errors.

Wrong: a CNAME and an MX record on one name.

shop.example.com. 3600 IN CNAME hosting.example.net.
shop.example.com. 3600 IN MX 10 mail.example.com.

Right: put the alias on a name with no other records.

www.example.com.  3600 IN CNAME hosting.example.net.
shop.example.com. 3600 IN MX 10 mail.example.com.

Wrong: an MX record value that is itself an alias. Right: the canonical name sits directly in the MX record.

; Wrong
example.com.      3600 IN MX 10 mail.example.com.
mail.example.com. 3600 IN CNAME hosting.example.net.
; Right
example.com.      3600 IN MX 10 hosting.example.net.

How to find, add and check a CNAME record

To check the CNAME record of a domain, use the CNAME lookup tool or dig:

dig CNAME shop.example.com +short

To add one, follow these provider-neutral steps. Field names vary by panel.

  1. Note the current records. A wrong change can break a site or mail.
  2. Open the DNS settings where the domain is managed. That is typically where it was bought, but it can differ if DNS hosting moved.
  3. Add a record with CNAME as the type.
  4. Enter the alias name. Many DNS panels append the domain to what you type, so check the field hints.
  5. Enter the full target name.
  6. Set the TTL and save.
  7. Run the dig command above.

Caches keep the old answer until the TTL expires. Google's documentation says changes can take up to 72 hours, though usually much sooner. Use the propagation checker to see what resolvers currently return.

References