Record types: A, AAAA, CNAME and TXT

Reading · 5 min · Module 5, lesson 2 of 416 min left in this module

Module 5 · DNSLesson 2 of 4

Goal: Read the four common DNS record types and choose the one a custom domain needs.

Key idea

Each DNS record answers one kind of question. A and AAAA point a name at an address, CNAME points it at another name, and TXT holds text that proves something about the domain. To put your own domain on a hosting platform, a subdomain almost always gets a CNAME.

The four you'll use

TypeIts valueUse it when
AAn IPv4 address, like 203.0.113.10Your host gives you an IPv4 address
AAAAAn IPv6 address, like 2001:db8::10Your host gives you an IPv6 address; add it next to the A record
CNAMEAnother name, like myapp.hosting.example.netYour host gives you a hostname to point at
TXTAny textA service asks you to prove you own the domain, or for email settings

A name can have several A records. The resolver returns all of them, and clients pick one, which spreads the load.

Why a CNAME is usually right

A CNAME says "this name is another name for that one". The resolver follows it to the target and returns the target's addresses. When the host moves your app to new addresses, it updates its own records, and your domain follows without you touching anything.

An A record can't do that. If the host changes the address, your domain points at the old one until you notice.

The bare domain can't be a CNAME

A name with a CNAME can't have any other records. The bare domain, example.com (called the apex), always carries other records, such as the ones naming its nameservers. So the apex can't be a CNAME. You have two options:

  • A and AAAA records with the addresses your host gives you for the apex.
  • An ALIAS, ANAME or "flattened CNAME", if your DNS host offers one. It looks like a CNAME to you, and your DNS host answers with the target's current addresses.

Choosing

  • app.example.com or www.example.com: a CNAME to the hostname your host gives you.
  • example.com: ALIAS if you have it, otherwise the A and AAAA addresses your host gives you.
  • A service asks for a TXT record: add it exactly as given. It proves ownership; it doesn't send any traffic.

In the Name field, most DNS hosts want only the part before your domain (app, not app.example.com), and @ for the apex.

Check yourself

Your host tells you to point www.example.com at myapp.hosting.example.net. Which record do you create?
Why can't example.com itself be a CNAME?

In the docs