askvity

What is a CNAME Record Example?

Published in DNS & Records 3 mins read

A CNAME record example is mapping a subdomain, such as www, to another domain name, indicating that the subdomain is an alias for the target domain.

Here's a breakdown with examples:

A CNAME (Canonical Name) record is a type of DNS (Domain Name System) record that maps an alias domain name (like a subdomain) to a canonical domain name (the actual domain hosting the content). It's essentially a shortcut or nickname for another domain. Instead of pointing directly to an IP address, a CNAME points to another domain name, which then resolves to an IP address.

Example Scenario:

Let's say you have a website hosted at example.com, and you want users to be able to access it using www.example.com. Instead of creating a separate A record for www.example.com that points to the same IP address as example.com, you can create a CNAME record.

CNAME Record Structure:

A typical CNAME record will look like this in your DNS settings:

Name (Host) Type Value (Target)
www CNAME example.com.

Explanation:

  • Name (Host): This is the alias you are creating (e.g., www).
  • Type: This specifies the record type, which is CNAME.
  • Value (Target): This is the canonical domain name that the alias points to (e.g., example.com). Note the trailing dot, which is a standard convention in DNS records, indicating the root domain.

How it Works:

  1. A user types www.example.com into their browser.
  2. The browser queries the DNS server for the IP address of www.example.com.
  3. The DNS server finds the CNAME record for www.example.com, which points to example.com.
  4. The DNS server then looks up the A record for example.com to find its IP address (e.g., 192.0.2.1).
  5. The DNS server returns the IP address (192.0.2.1) to the browser.
  6. The browser connects to the web server at that IP address and displays the website.

Another Example:

You might also use a CNAME record for a service like email:

Name (Host) Type Value (Target)
mail CNAME mail.examplehosting.com.

In this case, mail.example.com would be an alias that points to the mail server provided by your hosting provider (mail.examplehosting.com).

Important Considerations:

  • Root Domain: You typically cannot create a CNAME record for your root domain (e.g., example.com) because it conflicts with other essential DNS records like SOA (Start of Authority) and NS (Name Server) records.
  • Performance: CNAME records can slightly increase DNS lookup time because the DNS server has to perform an additional lookup to resolve the canonical name.
  • Other Record Types: CNAME records should not be used in conjunction with other record types (like A, MX, or TXT records) for the same name, as this can lead to conflicts and unpredictable behavior.

Related Articles