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.
sudo apt-get update
sudo apt-get install -y bind9-dnsutils dnsmasq-base
dig -vdig -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.
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 1Ubuntu'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.
dig @127.0.0.1 example.test A +noall +answer
dig @127.0.0.1 example.test AAAA +noall +answerYou get:
example.test. 0 IN A 192.0.2.10
example.test. 0 IN AAAA 2001:db8::10Read 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:
dig @127.0.0.1 example.test +shortStep 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.
dig @127.0.0.1 www.example.test CNAME +noall +answer
dig @127.0.0.1 www.example.test A +noall +answerThe 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:
www.example.test. 0 IN CNAME example.test.
example.test. 0 IN A 192.0.2.10Use 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 anALIASorANAMErecord 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.
dig @127.0.0.1 example.test MX +noall +answerexample.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:
dig @127.0.0.1 mail.example.test A +shortIt 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.comsays what to do with mail that fails those checks. - Verification tokens from services that ask you to prove you own the domain.
dig @127.0.0.1 example.test TXT +noall +answerexample.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:
dig @127.0.0.1 example.test ALook at three parts:
- The header line
status: NOERRORmeans the name exists and the query worked.NXDOMAINmeans the name does not exist at all.SERVFAILmeans the server could not get an answer. - The
flagsline containsaawhen the answer comes straight from the server that owns the zone (an authoritative answer), andrawhen it offers recursion. - The
Query timeandSERVERlines at the bottom show who answered, and how fast.
Ask about a name that does not exist, and print only the status:
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.1correctly.- 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
digstill shows the old one: other servers cache the answer until the TTL runs out. Ask the domain's own server withdig @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.
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 +shortNS records list the authoritative name servers, the machines that hold the domain's records. To ask one of them directly, skipping every cache:
dig @ns1.example.com example.com AReplace 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.
sudo pkill dnsmasqNext 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.
Related tutorials
- How to Put Nginx in Front of a Node.js App as a Reverse ProxyYou will install Node.js 26, run a small app on a local port, and configure Nginx 1.30 to pass public traffic to it with the headers your app needs.
- How to Load Balance Traffic Across Servers with NginxYou will spread requests across three backends with an Nginx upstream block, weight them, keep a spare in reserve, and watch Nginx route around a backend that stops answering.
- How to Install Nginx on Ubuntu 26.04You will install the current stable Nginx 1.30 from the official nginx.org repository on Ubuntu 26.04, serve its test page, and learn where its files live and how to reload it safely.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials