Kahibaro
Discord Login Register

12.4.3 CNAME

Understanding CNAME Records

What a CNAME Record Is

A CNAME record is a special type of DNS record that creates an alias from one domain name to another domain name. Instead of pointing directly to an IP address, a CNAME points to another hostname.

For example, if www.example.com is a CNAME to example.com, then whenever a client looks up www.example.com, DNS will say, in effect, “use example.com instead.” The client then resolves example.com to an IP address using other DNS records such as an A or AAAA record.

CNAME stands for “canonical name.” The target of a CNAME is called the canonical name, which means it is the primary, real hostname for that service.

How CNAME Resolution Works

When a resolver queries a name that has a CNAME record, it receives back another hostname instead of an IP address. The resolver then performs another DNS lookup for that hostname. This may happen more than once if there are chains of CNAMEs, although long chains are not recommended.

A simple sequence looks like this:

  1. Client asks DNS for www.example.com.
  2. DNS replies: www.example.com is a CNAME for example.com.
  3. Client now asks DNS for example.com.
  4. DNS replies with an A or AAAA record that contains the IP address.
  5. Client uses that IP address to connect.

The important point is that a CNAME never provides the IP itself. It always points to another name that eventually must resolve to an address record.

Typical Uses of CNAME

CNAME records are used when you want several different hostnames to point to the same underlying service, but you only want to manage the real address in one place.

A few common patterns are:

Using a friendly name for a service hosted elsewhere, such as app.example.com as a CNAME to myapp.hostingprovider.net.

Pointing multiple subdomains to a single canonical host, such as www.example.com and shop.example.com both as CNAMEs of example.com.

Delegating service names to another vendor, for example login.example.com as a CNAME to example.auth-provider.com.

This centralizes configuration so that if the canonical host’s IP changes, you only adjust the A or AAAA record for that one host. All CNAME aliases automatically follow the change.

Syntax and Structure

In a zone file or DNS configuration, a CNAME record typically has this structure:

Name, type, and target hostname.

An example:

www.example.com. 3600 IN CNAME example.com.

Here, www.example.com is the alias, CNAME is the record type, and example.com is the canonical name that will be resolved further.

You might also see shortened forms within a zone, such as:

www 3600 IN CNAME example.com.

In that case, www is relative to the zone, which might be example.com.

Important Rules and Limitations

CNAME records have strict rules that are easy to violate if you are not careful.

A name that has a CNAME record must not have any other DNS records of any type. It cannot have A, AAAA, MX, TXT, or any other record at the same name.

This means that if www.example.com is a CNAME record, you cannot also create an A record or MX record at www.example.com.

Another important practical rule concerns the zone apex, the root of your domain, like example.com itself. Traditional DNS rules and many providers do not allow the apex to be a CNAME. This is because the apex typically needs other record types, such as NS and SOA, which would break the rule above. Some DNS providers offer special solutions such as “ALIAS” or “ANAME” records that behave like CNAMEs but are not true CNAME records at the protocol level.

CNAME targets must be hostnames, not IP addresses. A CNAME that points to an IP address is invalid. The canonical name should eventually lead to A or AAAA records that contain the IP.

Finally, long chains of CNAMEs are technically allowed but discouraged. Each extra step requires another DNS lookup, which increases latency and may introduce more points of failure.

CNAME vs A and AAAA Records

A CNAME record never contains an IP address. It always redirects name resolution to another hostname. In contrast, A and AAAA records directly map a hostname to an IP address.

A simple comparison is helpful:

AspectCNAMEA / AAAA
Points toAnother hostnameAn IP address
Stores IP directlyNoYes
Can coexist at same name with other typesNoOften yes
Typical useAliases and indirectionDirect mapping to a server

Use CNAME when you want an alias that tracks another hostname. Use A or AAAA when you want a direct mapping to an IP address.

Practical Examples

Consider a website where example.com is the main address. You want www.example.com and blog.example.com to use the same server IP.

One approach is to create separate A records:

example.com IN A 192.0.2.10
www.example.com IN A 192.0.2.10
blog.example.com IN A 192.0.2.10

A CNAME-based approach centralizes this:

example.com IN A 192.0.2.10
www.example.com IN CNAME example.com
blog.example.com IN CNAME example.com

Now if the server IP changes, you only update the A record at example.com. The aliases stay correct without modification.

CDN providers and external SaaS services often instruct you to create CNAMEs that point your domain to a hostname that they control. This allows them to move or scale infrastructure behind that canonical name without asking you to change your DNS each time.

Misconfigurations to Avoid

There are a few common mistakes with CNAME records that cause problems:

Using CNAME at the apex of the zone in environments that do not support it. This can break necessary zone records.

Creating a CNAME and another record type at the same name. For instance, trying to configure mail.example.com as both a CNAME and the target of an MX or A record. This breaks the rule that a CNAME must be the only record at that name.

Pointing a CNAME directly to an IP address, such as www.example.com CNAME 192.0.2.10. This is invalid because the target must be a hostname.

Creating long CNAME chains, where one alias points to another alias several times. This can slow down lookups and may fail if there are resolver limits on how many steps are followed.

By respecting the specific rules that apply only to CNAME records, you can safely use them to simplify and centralize your DNS configuration without accidental outages.

Views: 44

Comments

Please login to add a comment.

Don't have an account? Register now!