Skip to main content

Web servers and networking · Beginner · 12 min

DNS Records Explained: A, AAAA, CNAME, MX and TXT, with dig Examples

By Padding · Updated 15 Nov 2026
dig (BIND 9) on Ubuntu 26.04.1 LTS

You will learn what the common DNS record types do and read each one with dig, using a small practice DNS server you start yourself.

On this page

A domain name is only a label. DNS, the Domain Name System, is the public directory that turns the label into the things a computer needs: the address of your web server, the server that takes your email, the text that proves you own the domain. Each entry in the directory is a record, and each record has a type.

When a website does not load or email goes missing, the cause is very often a wrong record. In this tutorial you will learn the five types you meet most, and read each one with dig, the standard tool for asking DNS questions. To keep the answers predictable, you will first run a tiny practice DNS server on your own machine and query that. The domain it serves, example.test, ends in .test, a name reserved so it never clashes with a real one.

Step 1 · Install dig and start a practice server

dig is in the bind9-dnsutils package on Ubuntu 26.04. The practice server is dnsmasq, set up with five records.

Bash
sudo apt-get update
sudo apt-get install -y bind9-dnsutils dnsmasq-base
dig -v

dig -v prints the version, DiG 9.20.24-1ubuntu0.5-Ubuntu or a later 9.20 build.

Start the practice server in the background. It listens only on your own machine, takes no outside answers, and holds only the records named on the command line.

Bash
sudo dnsmasq --no-resolv --no-hosts --listen-address=127.0.0.1 --bind-interfaces \
  --host-record=example.test,192.0.2.10,2001:db8::10 \
  --host-record=mail.example.test,192.0.2.25 \
  --cname=www.example.test,example.test \
  --mx-host=example.test,mail.example.test,10 \
  --txt-record=example.test,"v=spf1 mx -all" \
  --local=/example.test/
sleep 1

Ubuntu's own resolver, systemd-resolved, listens on 127.0.0.53, so it does not clash with this server on 127.0.0.1. If something else already holds port 53 on 127.0.0.1, dnsmasq stops with an error saying the address is in use.

The addresses 192.0.2.10 and 2001:db8::10 come from ranges set aside for documentation, so they point at nothing real.

Step 2 · A and AAAA records, the address of a server

An A record maps a name to an IPv4 address. An AAAA record (said "quad-A") maps it to an IPv6 address. This is the record that makes example.com open your web server.

The @127.0.0.1 part tells dig which DNS server to ask. +noall +answer trims the output to the answer lines.

Bash
dig @127.0.0.1 example.test A +noall +answer
dig @127.0.0.1 example.test AAAA +noall +answer

You get:

Text
example.test.		0	IN	A	192.0.2.10
example.test.		0	IN	AAAA	2001:db8::10

Read the columns left to right: the name (with a trailing dot, the root of DNS), the TTL in seconds, the class (IN for internet), the type and the value.

The TTL, the time to live, tells other servers how long they may remember the answer. Here it is 0 because the practice server sets none. On a real domain, you will see values such as 300 or 3600.

Check it worked

Each command prints one line, with 192.0.2.10 and 2001:db8::10. For a quick read of only the value, +short drops everything else:

Bash
dig @127.0.0.1 example.test +short

Step 3 · CNAME, an alias for another name

A CNAME record says "this name is an alias for that name". It does not hold an address. A resolver follows it, and asks about the target.

Bash
dig @127.0.0.1 www.example.test CNAME +noall +answer
dig @127.0.0.1 www.example.test A +noall +answer

The first command shows the alias, www.example.test. 0 IN CNAME example.test.. The second, asking for the address, shows both the CNAME and the final A record it leads to:

Text
www.example.test.	0	IN	CNAME	example.test.
example.test.		0	IN	A	192.0.2.10

Use a CNAME when many names should follow one: change the target's address once, and every alias follows. Three rules prevent most CNAME trouble.

  • A name with a CNAME cannot have any other record. That is why you cannot put a CNAME on the bare domain (example.com, the apex), which must also carry records such as MX and NS. Some DNS providers offer an ALIAS or ANAME record type as a workaround. These are provider features, not standard DNS.
  • A CNAME points to a name, never to an IP address.
  • Avoid chains of CNAMEs. Each one adds a lookup.

Step 4 · MX, where email goes

An MX record names the mail server that accepts email for a domain, with a priority number. The lowest number is tried first. If it is down, senders try the next.

Bash
dig @127.0.0.1 example.test MX +noall +answer
Text
example.test.		0	IN	MX	10 mail.example.test.

Read it as: mail for example.test goes to mail.example.test, priority 10. The target must be a name with an A or AAAA record. It cannot be an IP address and must not be a CNAME. Check that the mail server's own name resolves:

Bash
dig @127.0.0.1 mail.example.test A +short

It prints 192.0.2.25. If the MX target has no address, email to that domain fails, however well the rest is set up.

Step 5 · TXT, text for other systems

A TXT record holds a line of text. DNS does not interpret it. Other systems read it to check things about the domain. Common uses:

  • SPF (v=spf1 ...) lists the servers allowed to send email for the domain.
  • DKIM publishes a key at a name such as selector._domainkey.example.com, so receivers can verify mail signatures.
  • DMARC (v=DMARC1 ...) at _dmarc.example.com says what to do with mail that fails those checks.
  • Verification tokens from services that ask you to prove you own the domain.
Bash
dig @127.0.0.1 example.test TXT +noall +answer
Text
example.test.		0	IN	TXT	"v=spf1 mx -all"

This SPF value means: servers named in the domain's MX records may send mail, and everyone else is refused. A domain can hold several TXT records, but only one SPF record.

Step 6 · Read the whole answer, and a failed lookup

Without trimming options, dig shows the whole conversation:

Bash
dig @127.0.0.1 example.test A

Look at three parts:

  • The header line status: NOERROR means the name exists and the query worked. NXDOMAIN means the name does not exist at all. SERVFAIL means the server could not get an answer.
  • The flags line contains aa when the answer comes straight from the server that owns the zone (an authoritative answer), and ra when it offers recursion.
  • The Query time and SERVER lines at the bottom show who answered, and how fast.

Ask about a name that does not exist, and print only the status:

Bash
dig @127.0.0.1 nothing.example.test A +noall +comments | grep -o 'status: [A-Z]*'

The output is status: NXDOMAIN.

Troubleshooting

  • no servers could be reached: the DNS server is not running, or the address is wrong. Check it is up, and spell @127.0.0.1 correctly.
  • An answer section that is empty, with NOERROR: the name exists but has no record of the type you asked for. Ask for the right type.
  • You changed a record, and dig still shows the old one: other servers cache the answer until the TTL runs out. Ask the domain's own server with dig @ns1.example.com example.com A, to see the real value. Lower the TTL a day before a planned change.

Step 7 · Use the same commands on a real domain

On a real domain, you do not need @127.0.0.1. dig asks the resolver your machine already uses. Replace example.com with your domain.

Bash
dig example.com A +short
dig example.com AAAA +short
dig www.example.com CNAME +short
dig example.com MX +short
dig example.com TXT +short
dig example.com NS +short

NS records list the authoritative name servers, the machines that hold the domain's records. To ask one of them directly, skipping every cache:

Bash
dig @ns1.example.com example.com A

Replace ns1.example.com with a name from the NS result. To see the whole lookup from the root down, use dig example.com +trace. To look up the name behind an IP address (a reverse lookup), use dig -x 203.0.113.10 +short.

If you only want the final answer from a specific public resolver, such as Cloudflare's 1.1.1.1 or Google's 8.8.8.8, put it after the @.

Step 8 · Stop the practice server

When you are done, stop the practice DNS server.

Bash
sudo pkill dnsmasq

Next steps

  • Point your own domain at a server and serve it: /tutorials/host-multiple-sites-with-nginx-server-blocks.
  • Get a certificate for the name once its A record resolves: /tutorials/free-https-with-lets-encrypt-and-nginx.
  • Automatic certificates for the same job, with less setup: /tutorials/automatic-https-with-caddy-2.

Need this done for you?

Padding does this work for growing companies, from the first diagnosis to a system that keeps working.

Platform Engineering

Get new tutorials

New tutorials, about twice a month.