Skip to content
lorebow
All posts

Every DNS record, shown working

What DNS is, how one lookup travels the internet, and what A, AAAA, CNAME, MX, TXT, NS, SOA, PTR, SRV and CAA records actually do, each one animated.

KFounder and editor
6 min

Every time you open a website, send an email or install an app, your computer first asks one question: where is this name? People remember names like example.com; computers connect to numbers like 93.184.215.14. DNS, the Domain Name System, is the internet's phone book that turns one into the other, and it does a lot more besides.

This post shows it working rather than describing it. Every figure below plays by itself when you scroll to it, and you can pause, step or switch scenarios.

#What happens when you type a name

Four kinds of servers took part:

  • Your resolver does the legwork. It belongs to your internet provider, your office, or a public service like 1.1.1.1 or 8.8.8.8.
  • Root servers sit at the top. They only know who runs each ending (.com, .org, .my).
  • TLD servers (top-level domain) know who answers for each name under their ending.
  • The authoritative server for example.com holds its actual records. This is where you, the domain owner, make changes.

The second scenario is the one that happens almost every time: the answer comes from a cache. How long it stays there is the record's TTL (time to live), in seconds.

#A zone is a cabinet of records

Everything the authoritative server knows about your domain is one zone. A zone is a list of records, and each record has a name, a TTL, a type and a value. The type decides which question it answers. Ask the cabinet a question:

A zone is a cabinet of recordsA record
example.comAAAACNAMEMXTXTNSSOAPTRSRVCAAA
In the zone fileHow A works ↓
example.com.   3600 IN A     93.184.215.14

A resolver never asks for "everything about example.com". It always asks for one name and one type, and opens only that drawer. The rest of this post opens each drawer in turn.

#A and AAAA

An A record maps a name to an IPv4 address. An AAAA record maps it to an IPv6 address. These are the records almost every domain has.

dig
$ dig example.com A +noall +answer
example.com.    3600  IN  A     93.184.215.14
$ dig example.com AAAA +noall +answer
example.com.    3600  IN  AAAA  2606:2800:21f:cb07::68

Before any of this, your computer checks its own hosts file (/etc/hosts, or C:\Windows\System32\drivers\etc\hosts). A line like 127.0.0.1 example.com there wins over DNS, which is handy for testing a site before you switch the real records over.

#CNAME

A CNAME (canonical name) says "this name is an alias; go and ask about that other name instead". It never holds an address itself.

dig
$ dig shop.example.com +noall +answer
shop.example.com.          3600  IN  CNAME  stores.shopcloud.net.
stores.shopcloud.net.       300  IN  A      203.0.113.10

Two rules catch people out:

  • A CNAME can't share its name with anything else. If shop is a CNAME, it can't also have an MX or TXT record.
  • So it can't sit on the bare domain (example.com itself), which always has NS and SOA records. Many DNS hosts offer a non-standard ALIAS, ANAME or "CNAME flattening" record for that case: it follows the alias on their side and answers with plain A records.

#MX

An MX (mail exchanger) record says which servers accept email for the domain, each with a priority. Lower numbers are tried first.

dig
$ dig example.com MX +noall +answer
example.com.    3600  IN  MX  10 mx1.example.com.
example.com.    3600  IN  MX  20 mx2.example.com.

The value is a name, never an IP address, and that name needs its own A or AAAA record. It must not be a CNAME. Without any MX record, senders fall back to the domain's A record, which is rarely what you want.

#TXT

A TXT record holds free text. DNS doesn't care what it says, but other systems read it, so in practice it's how a domain publishes small facts about itself:

  • SPF: which servers may send mail as this domain (shown below).
  • DKIM: the public key that checks the signature on each email, at a name like selector._domainkey.example.com.
  • DMARC: what receivers should do when SPF or DKIM fail, at _dmarc.example.com.
  • Proof of ownership: services like Google Search Console ask you to add a random string to show you control the domain.
dig
$ dig example.com TXT +noall +answer
example.com.    3600  IN  TXT  "v=spf1 ip4:198.51.100.0/24 -all"
$ dig _dmarc.example.com TXT +short
"v=DMARC1; p=reject; rua=mailto:dmarc@example.com"

#NS

NS (name server) records say which servers are authoritative for a zone. The ones that matter most are the copies held by the parent zone: the .com servers keep the NS records for example.com, and that is how resolvers find your zone at all. This is called delegation.

dig
$ dig example.com NS +noall +answer
example.com.   86400  IN  NS  ns1.example.com.
example.com.   86400  IN  NS  ns2.example.com.

NS records usually have long TTLs, often a day or two. When you move DNS hosts, copy every record to the new host first, change the name servers at your registrar, and keep the old host answering until those TTLs have passed.

#SOA

Every zone starts with exactly one SOA (start of authority) record. It names the primary server and an admin contact, and it carries a serial number and timers that tell secondary servers how often to check for changes.

dig
$ dig example.com SOA +noall +answer
example.com.  3600  IN  SOA  ns1.example.com. admin.example.com. 2026102401 7200 3600 1209600 3600

Read the value left to right: primary server, admin email (the first dot is the @), serial, refresh (how often secondaries check, here 2 hours), retry (if that check fails), expire (when a secondary that can't reach the primary gives up, here 14 days), and the negative TTL: how long resolvers cache "this name doesn't exist". Serials are often written as a date plus a counter, YYYYMMDDnn.

#PTR

A PTR (pointer) record goes the other way: from an IP address back to a name. The address is written backwards under a special domain, so 93.184.215.14 becomes 14.215.184.93.in-addr.arpa (IPv6 uses ip6.arpa).

dig
$ dig -x 93.184.215.14 +noall +answer
14.215.184.93.in-addr.arpa.  3600  IN  PTR  mail.example.com.

The reverse zone belongs to whoever owns the IP address, usually your hosting provider or ISP. You can't add a PTR in your own DNS panel; you set it in your server host's dashboard or ask them. It matters mostly for mail servers: without a matching PTR, your email is likely to be marked as spam.

#SRV

An SRV (service) record tells a program where a service runs: which host, which port, and in which order to try them. Its name says which service and protocol it's for, like _xmpp-client._tcp.example.com.

dig
$ dig _xmpp-client._tcp.example.com SRV +noall +answer
_xmpp-client._tcp.example.com.  3600  IN  SRV  10 5 5222 chat.example.com.

The four values are priority (lowest first, like MX), weight (how to share load between records with the same priority), port and target host. Browsers don't use SRV; chat, voice, game servers and directory services do.

#CAA

A CAA (certification authority authorization) record lists which certificate authorities may issue TLS certificates for your domain. Every public CA must check it before issuing.

dig
$ dig example.com CAA +noall +answer
example.com.    3600  IN  CAA  0 issue "letsencrypt.org"
example.com.    3600  IN  CAA  0 iodef "mailto:security@example.com"

issue allows a CA, issuewild controls wildcard certificates, and iodef gives an address the CA can report refused requests to. No CAA record at all means any CA may issue, so adding one is a cheap way to shrink the number of places a certificate for your domain could come from.

#Compare any records

Some records get mixed up all the time: A and CNAME both "point a name somewhere", MX and SRV both name a server, NS and SOA both sit at the top of every zone. DNS record types compared puts any two or three side by side: what each answers, what it holds, whether it can sit on the bare domain, and the mistake people make with it.

#Which record answers which question

You want to…RecordExample value
Point a name at a server (IPv4)A93.184.215.14
Point a name at a server (IPv6)AAAA2606:2800:21f:cb07::68
Make one name an alias of anotherCNAMEstores.shopcloud.net.
Receive emailMX10 mx1.example.com.
Publish SPF, DKIM, DMARC or a proofTXT"v=spf1 ip4:198.51.100.0/24 -all"
Say which servers answer for the domainNSns1.example.com.
Version the zone for secondary serversSOAns1… admin… 2026102401 7200 …
Turn an IP address back into a namePTRmail.example.com.
Say where a service runs, with its portSRV10 5 5222 chat.example.com.
Limit who can issue certificatesCAA0 issue "letsencrypt.org"

Next time something "doesn't resolve", ask the same question the resolver asks, one name and one type at a time, with dig name TYPE. The answer, or the empty drawer, will tell you where to look.