Check DNS records with dig
dig is a command line tool that asks a DNS server for the records of a domain, so you can see what the internet will resolve it to.
- Updated Nov 27, 2026
- Markdown
Look up a domain's DNS records with dig and ask a chosen resolver or nameserver.
- A terminal on your server or computer
- A domain you can look up
A site works from your laptop but not from a friend’s phone, or you changed a record an hour ago and nothing seems different. A browser tells you very little about why. dig asks DNS directly and shows exactly what each server answers, including how long the answer may be cached.
How it works#
DNS is a chain of lookups. Your computer asks a recursive resolver (your ISP’s, or a public one such as 1.1.1.1). If the resolver has no fresh cached answer, it walks down from the root servers to the domain’s authoritative nameservers, which hold the real records. It then caches the answer for the record’s TTL and returns it to you.
So two kinds of server can answer a dig. A resolver gives you the cached view, which may be old. An authoritative server gives you the configured truth. Comparing them is the main debugging trick in DNS.
A reply has a status. NOERROR means the query worked, even if the answer section is empty. NXDOMAIN means the name does not exist. SERVFAIL means the resolver could not get a valid answer. Reading that status first saves a lot of guessing.
Also remember that A records hold IPv4 addresses and AAAA records hold IPv6 addresses. A name can have both, and clients will often prefer IPv6 when it is present.
Step 1: Install dig#
On Ubuntu and Debian the tool comes in the dnsutils package:
sudo apt update
sudo apt install dnsutilsOn macOS it is already installed. Newer Debian and Ubuntu releases may name the package bind9-dnsutils, which apt pulls in through dnsutils.
What you should see: dig -v prints a version line.
Step 2: Look up an A record#
dig example.com AFind the ANSWER SECTION. It lists the name, the TTL in seconds, the class IN, the type A and the IPv4 address. The header line shows status: NOERROR on success. For a short output:
dig +short example.com AWhat you should see: one or more IP addresses, one per line. Run it twice a few seconds apart on a cached name and the TTL in the long form counts down.
Step 3: Pick which resolver to ask#
dig +short example.com A @1.1.1.1The part after @ is the server you query. Without it, dig uses your system’s resolver, which may cache. Try @8.8.8.8 as a second opinion.
What you should see: the same address, or an older one if that resolver has not refreshed.
Step 4: Look up nameservers and ask them directly#
dig +short example.com NSThis lists the authoritative nameservers. Ask one of them for the answer straight from the source:
dig +short example.com A @ns1.example.netReplace ns1.example.net with a name from the previous command. The authoritative server is not cached, so it shows the record as you configured it.
What you should see: your current configured value. If this is wrong, fix it at your DNS provider. If it is right but a resolver is wrong, wait for the cache to expire.
Step 5: Check other record types and the whole path#
dig +short example.com AAAA
dig +short example.com MX
dig +short example.com TXT
dig +trace example.com A+trace does the walk from the root servers itself, so it ignores your resolver’s cache. It prints each step down to the authoritative answer.
What you should see: for +trace, a series of blocks listing root servers, then the .com servers, then your domain’s nameservers, and finally the answer.
Check it worked#
You are looking for the IP address of your server in the output. For a record you just created, the authoritative query should return the new address, and a public resolver such as @1.1.1.1 should match it once its cache has refreshed. Empty output from +short means no record of that type was found for that name.
Alternative: nslookup#
nslookup example.com
nslookup example.com 1.1.1.1The second form asks the resolver at 1.1.1.1. The answer appears under “Non-authoritative answer” when it came from a cache.
Edge cases and gotchas#
- dig asks for A only by default. If your site is IPv6 only or you set a CNAME, a plain
digcan look empty. QueryAAAAorCNAMEby name. - A stale IPv6 record sends some visitors to the old server. You updated the A record but forgot the AAAA record. Check both.
- The system resolver may be a local stub. On Ubuntu,
digwithout@often asks a local resolver at127.0.0.53. Use@1.1.1.1to bypass it. - A CNAME at the root cannot coexist with other records. The bare domain normally needs A or AAAA records. Your provider may offer an alias-style record instead.
- Wrong name, right record.
example.comandwww.example.comare separate names. Check the exact one visitors use. - Trailing dot and search domains.
dig hostmay try your machine’s search suffixes. A fully qualified name ends with a dot, as inexample.com.. - Negative answers are cached too. If you looked up a name before you created it, resolvers may remember NXDOMAIN for a while. Ask the authoritative server for the real state.
Troubleshooting#
| Symptom | Likely cause | Fix |
|---|---|---|
command not found: dig | dnsutils not installed | Install dnsutils as in Step 1 |
status: NXDOMAIN | Name does not exist | Check the spelling and add the record at your DNS provider |
status: SERVFAIL | Resolver cannot get a valid answer, often a broken or mismatched nameserver setup | Try another resolver, check the domain’s nameserver settings |
status: NOERROR with empty answer | Name exists but not that record type | Query the right type, or add the record |
;; communications error or connection timed out; no servers could be reached | Resolver unreachable or port 53 blocked | Try @1.1.1.1, check the network and firewall |
| Resolver answer differs from authoritative | Cache not expired yet | Wait out the TTL, then query again |
+short prints a name, not an IP | Record is a CNAME | Follow the target with a second query |
| Answer is a different IP than the provider panel shows | Asking a cache, or editing the wrong zone | Ask @ the authoritative server from NS |
Real-world scenario#
You pointed example.com at a new server an hour ago and a teammate says it still loads the old one. You start with the authoritative server, since it is the truth:
dig +short example.com NS
dig +short example.com A @ns1.example.netIt returns 203.0.113.10, the new address. Then you ask public resolvers:
dig +short example.com A @1.1.1.1
dig +short example.com A @8.8.8.8One returns the new address, the other the old one. So the change is saved and one cache has not expired. Running dig example.com A @8.8.8.8 without +short shows the remaining TTL counting down, which tells you roughly when it will refresh. Last, you check dig +short example.com AAAA and find an old IPv6 address that nobody updated. That explains why your teammate on an IPv6 network still sees the old site. You fix the AAAA record, and the story ends there. For what the TTL means for timing, see DNS propagation and TTL.
Quick reference#
dig example.com A # full answer with TTL
dig +short example.com A # just the value
dig +short example.com AAAA # IPv6
dig +short example.com NS # authoritative servers
dig +short example.com MX # mail
dig +short example.com A @1.1.1.1 # ask a specific resolver
dig +trace example.com A # walk from the root, no cache
dig -x 203.0.113.10 # reverse lookupRelated lessons#
- DNS record types explained: what A, AAAA, CNAME, MX and TXT mean.
- Point a domain at your server: the records you are checking here.
- Inspect a TLS certificate with OpenSSL: the next check after DNS is right.
Next#
Now see why a change takes time to show up in DNS propagation and TTL.
Check what you learned
Frequently asked questions
What does +short do?
It prints only the answer values, such as an IP address, and hides the headers and extra sections. It is handy for quick checks and scripts.
Why do two resolvers give different answers?
Resolvers cache answers. If a record was changed recently, one may still hold the old value until its cache expires.
dig shows the right IP but my browser goes to the old server. Why?
The browser and operating system keep their own DNS caches, and dig may be asking a different resolver. Also check for an old entry in /etc/hosts and for an IPv6 (AAAA) record.
Why does dig example.com print nothing for a record I know exists?
By default dig asks for the A record only. Name the type you want, for example dig example.com MX or dig example.com TXT, and make sure you asked the right name.
Keep going: guides and tutorials
- Self-Hosted Static Site Hosting: Deploy a Folder With Levelrail Self-hosted static site hosting from a plain folder: one deploy command, _redirects, _headers and a custom 404 honored, plus a one command rollback.
- Deploy Next.js on a VPS With Docker, Git Push and HTTPS Deploy a Next.js app to your own VPS with Docker, a health check, HTTPS and rollback. Includes the NEXT_PUBLIC build trap that leaves variables empty.