Skip to main content

What is CNAME?

CNAME (Canonical Name) is a DNS record that makes one domain name an alias for another domain name.

In simpler terms: CNAME says: "this name is just another name for another domain".


Why CNAME is needed

CNAME is used to:

  • point several names at the same resource
  • avoid duplicating IP addresses in DNS
  • simplify managing domains and subdomains

For example:

www.example.com -> example.com

www.example.com is not a separate site, just another name for example.com.


How CNAME works

  1. The client requests:
www.example.com
  1. DNS sees the CNAME:
www.example.com -> example.com
  1. DNS then looks up records for example.com
  2. It finds an A / AAAA record and returns the IP

A CNAME does not contain an IP address itself.


Example of a CNAME record

Simplified:

NameTypeValue
www.example.comCNAMEexample.com
example.comA93.184.216.34

In total: www.example.com -> example.com -> 93.184.216.34


Important CNAME restrictions

This is often asked in interviews:

A CNAME cannot be used for the domain root (example.com) (in classic DNS)

A name with a CNAME must not have other DNS records (A and CNAME cannot coexist)

So:

  • www.example.com -> CNAME is fine
  • example.com -> usually A / AAAA

When CNAME is especially useful

  • CDNs (Cloudflare, CloudFront, etc.)
  • external services (GitHub Pages, Heroku)
  • when the IP can change often
  • when one service needs to be reachable under different names

Real-life example

CNAME is like:

  • a person's alias
  • there is one real name, but you can address them differently

Short interview answer

Remember this formulation:

CNAME is a DNS record that indicates one domain name is an alias for another domain name, and it redirects DNS resolution to it.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.