Guides

CNAME vs A Record vs ALIAS: Which One Should You Use?

A records point to an IP, CNAMEs point to another name, and ALIAS or ANAME records solve the root domain problem. Learn when to use each and the rules.

By Zebra Hosting Cloud

When you add a record in a DNS panel, the first decision is the type. A, CNAME and ALIAS all make a name lead somewhere, but they work differently, and choosing wrong can break email or stop a site from loading. This article explains each, the rules that apply, and a simple way to decide.

A and AAAA records

An A record maps a name directly to an IPv4 address. An AAAA record does the same for IPv6.

example.com.      3600  IN  A     203.0.113.20
www.example.com.  3600  IN  A     203.0.113.20

Use A records when you know the IP of the server and it is stable, such as a web server you control. If the server's IP changes, you must update the record yourself.

CNAME records

A CNAME says "this name is an alias of that name". The resolver then looks up the target name instead.

www.example.com.   3600  IN  CNAME  example.com.
shop.example.com.  3600  IN  CNAME  stores.provider.net.

CNAMEs are ideal when a third-party service gives you a hostname and may change its IP addresses at any time. You point to their name, and they keep it up to date. They are also useful for keeping several names in step with one main name.

The rules of CNAME

  • A name with a CNAME cannot have any other record type. No MX, no TXT, no A.
  • Because the apex (root) of a domain must have SOA and NS records, a standard CNAME cannot be placed there.
  • Do not point a CNAME at another CNAME in long chains. It is allowed, but each hop adds lookup time and risk.
  • An MX record must not point to a name that is itself a CNAME.

The root domain problem and ALIAS records

Many people want example.com itself, not just www, to point to a service that only provides a hostname, such as a hosted shop or a load balancer. A CNAME is not allowed at the apex, so some DNS providers offer a special record type, called ALIAS, ANAME or "CNAME flattening". The provider's name servers resolve the target hostname themselves and answer with the resulting A and AAAA records.

These are not part of the core DNS standards, so the name and behaviour differ between providers. Read your provider's documentation, and note that a flattened record answers with addresses that are only as fresh as the provider's own refresh interval.

Comparison

A / AAAACNAMEALIAS / ANAME
Points toIP addressAnother hostnameAnother hostname
Allowed at apexYesNoYes (that is its purpose)
Coexists with MX and TXTYesNoYes
Follows target IP changesNoYesYes, via the provider
Standard across providersYesYesNo

Simple decision guide

  1. Do you know a fixed IP address for the target? Use an A (and AAAA if IPv6 exists).
  2. Is the target a hostname supplied by a service, and the name you are setting up is a subdomain such as www or shop? Use a CNAME.
  3. Is the name the root domain, and the target is a hostname? Use ALIAS or ANAME if your DNS provider supports it. Otherwise ask the service for fixed IPs.

Frequent mistakes

CNAME on a name with email

If you add a CNAME to a name that already has MX or TXT records, the DNS host may refuse it, or may silently drop the other records, depending on the software. Mail then stops. Check for existing records before adding a CNAME.

Wrong target format

Some panels expect the target with a trailing dot, and some add it for you. A missing dot can turn the target into target.example.com.example.com. Check the saved result.

Using a CNAME with a CDN or proxy

Services that proxy your traffic, including many CDNs, often provide a hostname for CNAME setup or handle the root through their own flattening. Follow their instructions to the letter, and be aware that proxying applies to web traffic only, never to mail records.

Forgetting verification records

Many services ask for a TXT record for domain verification. That TXT cannot sit at a name that already holds a CNAME, so they sometimes give a special subdomain for it.

Check your work

After saving, query the name with dig or an online lookup. For a CNAME, you should see the alias and then the final address. Confirm that mail still works if you changed anything near the domain root.

Why hosts sometimes ask for A records only

Some platforms insist on A records for the root domain and a CNAME for www. That is intentional: it works with every DNS provider, and the pair covers both forms of the address. A common pattern is to point the root A record at the host's IP, make www a CNAME to the root, and redirect one form to the other at the web server so visitors and search engines see a single address.

Records and hosting with Zebra Hosting

For sites on Zebra Hosting, DNS can be managed in Plesk, and Cloudflare CDN is available on hosted sites, so the right records for your setup are usually quick to set. Support in 17 languages can confirm the correct type for your case. Read more about the CDN or browse the knowledge base.