5 DNS Tools Every Linux Admin Should Know
When a site won't load, a mail server rejects your messages, or a new record "isn't working yet", you end up at a shell prompt asking DNS questions. Five tools cover most of that work on Linux: dig and nslookup for queries, dnsmasq for a local cache and DHCP, BIND for running real zones, and whois for the registration side.
The examples below use example.com and public resolvers like 8.8.8.8 and 1.1.1.1. Swap in your own domain and servers.
1. dig
dig (Domain Information Groper) ships with BIND's utilities. On Debian and Ubuntu install dnsutils (or bind9-dnsutils); on RHEL, Fedora and Rocky install bind-utils. Most admins reach for it first because it prints the raw DNS response with no reformatting.
Everyday queries
dig example.com # A record, full output
dig example.com +short # answer only
dig MX gmail.com +short # mail servers with priority
dig TXT example.com +short # SPF, DKIM, verification tokens
dig -x 1.1.1.1 +short # reverse (PTR) lookup
Sample output from the MX query:
5 gmail-smtp-in.l.google.com.
10 alt1.gmail-smtp-in.l.google.com.
20 alt2.gmail-smtp-in.l.google.com.
Ask a specific server
Put the server after an @. Comparing your resolver with a public one, and with the domain's authoritative server, tells you where a stale or wrong answer comes from:
dig @8.8.8.8 example.com A +noall +answer
dig @1.1.1.1 example.com A +noall +answer
dig NS example.com +short # find the authoritative servers
dig @ns1.yourdnshost.com example.com A # ask one directly
+noall +answer hides everything except the answer section, so you see the record and its remaining TTL:
example.com. 300 IN A 104.20.23.154
Follow the delegation chain
dig +trace example.com starts at the root servers and follows each referral down to the authoritative answer. Use it when a domain resolves for some people and not others, or right after you change nameservers at the registrar.
Read the timing
The footer of a full dig response includes ;; Query time: 23 msec and ;; SERVER:. Run the same query twice: the second run should come back in a few milliseconds from cache. If both runs are slow, your resolver is the bottleneck.
2. nslookup
nslookup comes from the same package as dig on Linux, and it also exists on Windows and macOS. If you support mixed environments, you can send the same command to a Windows colleague and compare results.
nslookup example.com # A/AAAA via your default resolver
nslookup example.com 8.8.8.8 # use a specific server
nslookup -type=MX gmail.com # other record types
nslookup 1.1.1.1 # reverse lookup
Output looks like this:
Server: 192.168.1.1
Address: 192.168.1.1#53
Non-authoritative answer:
gmail.com mail exchanger = 5 gmail-smtp-in.l.google.com.
"Non-authoritative" means a caching resolver answered, not the zone's own nameserver.
Run nslookup with no arguments to enter interactive mode. You can then type set type=TXT, server 1.1.1.1 and a series of names without restarting the tool.
You may read that nslookup is deprecated. ISC added that notice in the BIND 9 era and withdrew it later, so the tool is still maintained. Prefer dig in scripts because its output is easier to parse, and keep nslookup for quick checks and cross-platform work.
3. dnsmasq
dnsmasq is a small DNS forwarder, cache and DHCP server in one process. You'll find it inside home routers, libvirt and many container setups. On a workstation or a small office network it gives you local caching and custom hostnames with a few lines of config.
Install it with apt install dnsmasq or dnf install dnsmasq. The main config file is /etc/dnsmasq.conf, and most distributions also read drop-ins from /etc/dnsmasq.d/.
A minimal setup for a dev machine:
# /etc/dnsmasq.d/local.conf
listen-address=127.0.0.1
no-resolv
server=1.1.1.1
server=8.8.8.8
cache-size=1000
# send *.test to localhost
address=/test/127.0.0.1
# fixed name for a box on the LAN
address=/nas.home.lan/192.168.1.20
With that file in place, app.test, api.test and any other *.test name resolve to 127.0.0.1, which saves you from editing /etc/hosts for every project. Use .test rather than .dev or .local: .dev is a real Google-owned TLD and .local belongs to mDNS.
Check the syntax, restart, and query it:
dnsmasq --test
sudo systemctl restart dnsmasq
dig @127.0.0.1 app.test +short
On Ubuntu and other systemd distributions, systemd-resolved already listens on 127.0.0.53:53. If dnsmasq fails to start with "address already in use", either bind dnsmasq to a different address or disable the stub listener (DNSStubListener=no in /etc/systemd/resolved.conf).
dnsmasq also hands out DHCP leases (dhcp-range=192.168.1.50,192.168.1.150,12h) and can serve PXE boot files over its built-in TFTP server. For authoritative public zones, use BIND or another dedicated server instead.
4. BIND
BIND (Berkeley Internet Name Domain), maintained by ISC, is the reference DNS server implementation and one of the most deployed. Its named daemon can act as an authoritative server for your zones, a recursive resolver, or both. It supports DNSSEC signing and validation, zone transfers, views (split-horizon DNS) and dynamic updates.
Package names are bind9 on Debian and Ubuntu and bind on RHEL-family systems. The main config is /etc/bind/named.conf on Debian-based systems and /etc/named.conf on RHEL.
A zone declaration:
zone "example.com" {
type primary;
file "/etc/bind/db.example.com";
};
And a small zone file:
$TTL 3600
@ IN SOA ns1.example.com. hostmaster.example.com. (
2024061501 ; serial
3600 ; refresh
900 ; retry
1209600 ; expire
300 ) ; negative cache TTL
IN NS ns1.example.com.
IN NS ns2.example.com.
@ IN A 203.0.113.10
www IN CNAME example.com.
@ IN MX 10 mail.example.com.
mail IN A 203.0.113.20
Older configs use type master; and type slave;. BIND 9.16 and later accept primary and secondary as the same thing.
The tools that save you from outages come bundled with BIND:
named-checkconf # validate named.conf
named-checkzone example.com /etc/bind/db.example.com # validate a zone file
sudo rndc reload example.com # load the zone without a restart
sudo rndc flush # clear the resolver cache
Run named-checkzone before every reload, and bump the SOA serial each time you edit a zone. Secondary servers compare serials to decide whether to pull a new copy, so a forgotten serial bump leaves them serving old data.
5. whois
whois queries registration data: the registrar, creation and expiry dates, domain status codes and the nameservers set at the registry.
whois example.com
whois example.com | grep -iE 'registrar:|expiry|name server|status'
whois 8.8.8.8 # IP ownership from the regional internet registry
Two changes affect what you get back:
- Privacy redaction. Since GDPR took effect in 2018, most registrars hide the registrant's name, email and address. Expect "REDACTED FOR PRIVACY" or a proxy contact. Registrar, dates, status and nameservers still show up.
- RDAP. ICANN replaced WHOIS with RDAP for generic TLDs (.com, .net, .org and others) in January 2025. Registries return RDAP as JSON over HTTPS. The
whoiscommand still works for many domains, but if it returns nothing useful, query RDAP directly:curl -s https://rdap.org/domain/example.com | jq .
For DNS troubleshooting, the useful fields are the nameservers (do they match the ones you expect?) and the status. A status of clientHold or serverHold takes the domain out of DNS entirely, which looks like a DNS failure but needs a fix at the registrar. An expired domain shows the same symptom, so check the expiry date too.
Troubleshooting with these tools
A record change "hasn't propagated"
DNS doesn't push changes. Resolvers keep the old answer until its TTL runs out. Query the authoritative server with dig @ns1.yourdnshost.com example.com; if it returns the new value, your change is live and resolvers will pick it up when the cached TTL expires. A 3600-second TTL means up to an hour. Lower the TTL a day before planned changes. If you changed nameservers at the registrar, the parent zone's NS records carry their own TTL, often 48 hours for .com.
Lookups are slow
Compare ;; Query time: from your configured resolver against dig @1.1.1.1. If the public resolver answers fast and yours doesn't, the problem is your resolver or the path to it. Check /etc/resolv.conf, or run resolvectl status on systemd-resolved hosts to see which upstream servers the machine uses.
A domain doesn't resolve at all
Work down the chain. dig +trace example.com shows where it breaks. SERVFAIL on a DNSSEC-signed zone often means broken signatures; test with dig +cd example.com (checking disabled), and if that succeeds, the DNSSEC setup is at fault. NXDOMAIN from the authoritative server means the record doesn't exist there. No delegation at all points to registrar status or expiry, which whois will show.
Your own DNS server won't answer
Confirm the daemon runs (systemctl status named or systemctl status dnsmasq), that it listens on port 53 (ss -lunp | grep :53), and that the firewall allows UDP and TCP 53. For BIND, run named-checkconf and named-checkzone, then read journalctl -u named for zone load errors.
Mail bounces or lands in spam
Check dig MX example.com +short and dig TXT example.com +short for SPF, then dig TXT selector._domainkey.example.com for DKIM and dig TXT _dmarc.example.com for DMARC. Two SPF records on the same name is a common mistake: receivers treat it as an error.
Other tools worth knowing
host: a terse lookup tool in the same package asdig.host -t MX example.comgives one line per record.drill: from the ldns package, withdig-like syntax and good DNSSEC tracing (drill -TD example.com).kdig: from Knot DNS, supports DNS over TLS and DNS over HTTPS (kdig +tls @1.1.1.1 example.com).resolvectl query example.com: shows how a systemd-resolved host resolves a name, including which interface and server answered.
Start with dig and whois. Most DNS problems you'll see come down to a record that's wrong at the source, a cached answer that hasn't expired, or a domain the registrar has put on hold, and those two tools tell you which.