The CNAME (Canonical Name Record) is a type of DNS record that maps one domain name (an alias) to another domain name (the canonical name). Essentially, it redirects queries from the alias to the target canonical domain, where it can find the appropriate records.

Characteristics of a CNAME Record:

  1. Purpose: To provide an alias for another domain name, which then handles the queries.
  2. Format: The record consists of an alias name and the target canonical domain name.
  3. Example:
   www.example.com.  IN  CNAME  example.com.

In this example, when someone accesses www.example.com, the DNS system uses the CNAME record to redirect the query to example.com. Any subsequent lookups (e.g., for an A or AAAA record) are then done using example.com.

Key Points:

  • Usage: CNAME records are often used for subdomains. For example, you might want blog.example.com to point to the same place as example.com, so you’d set up a CNAME record to make that happen.
  • Limitations: You cannot have any other records for a domain that has a CNAME record. That means if www.example.com is a CNAME to example.com, www.example.com cannot have its own MX or TXT records.
  • DNS Resolution: When a resolver encounters a CNAME record, it will resolve the CNAME alias to its canonical name, and then make an additional request to get the actual IP address associated with that canonical name.
  • No CNAME Chaining: It’s a bad practice to point a CNAME record to another CNAME record (known as chaining). It can lead to increased DNS lookup times and potential resolution failures.
  • Apex of a Domain: Due to the restrictions of CNAME records, you can’t use them at the apex (root) of a domain. Some providers offer “ANAME” or “ALIAS” records to get around this limitation.

CNAME records provide flexibility in DNS management, allowing administrators to alias one domain to another and making it easier to manage and reconfigure infrastructure as needs change.