getent hosts example.comhow the system actually resolves it (for apps)
resolvectl statusDNS servers and search domains
dig +short example.coma quick answer (IP only)
dig example.com MXa specific record type
dig @8.8.8.8 example.comcheck via a public DNS server
dig +trace example.comwhere delegation breaks
resolvectl flush-cachesclear the cache
local overrides go in /etc/hosts; permanent ones in netplan's nameservers
Overview
To reach example.com, the system turns the name into an IP. The order of
sources is set by NSS (/etc/nsswitch.conf): usually /etc/hosts first, then
DNS.
On Ubuntu, DNS resolution is handled by systemd-resolved, and
/etc/resolv.conf is a symlink to its stub (127.0.0.53).
bash
getent hosts example.com # how the system ACTUALLY resolves it (hosts+DNS+NSS)
resolvectl status # current DNS servers and search domains per interface
resolvectl query example.com # a query through systemd-resolved (as an app would see it)
Important: dig/nslookup go directly to DNS, while applications
resolve through NSS. So for "what the program sees", use getent
hosts/resolvectl query; use dig to check the DNS server itself.
Options
/etc/hosts — local overrides (usually take priority over DNS):
getent hosts myserver # check the system sees the override
resolvectl flush-caches # clear systemd-resolved's cache
resolvectl statistics # cache hits/misses
Recipes
1
dig / host / nslookup
bash
dig example.com # a detailed DNS query (package dnsutils/bind9-dnsutils)
dig +short example.com # answer only (IP) — handy in scripts
dig +short example.com AAAA # the IPv6 address
dig example.com MX # a record type (A, AAAA, MX, TXT, NS, SOA, CNAME…)
dig @8.8.8.8 example.com # ask a SPECIFIC server (bypassing the local one)
dig +trace example.com # walk delegation from the root (where it breaks)
dig -x 1.2.3.4 # a reverse lookup (PTR)
dig +noall +answer example.com # only the answer section
host example.com # short and simple
host -t MX example.com # a record type
nslookup example.com # the classic (also interactive)
Troubleshooting
5
SymptomCause and fix
IPs ping, but names don't
DNS isn't working. Work down the ladder:
1. resolvectl status — does the interface have a DNS server (Current DNS Server)?
2. getent hosts example.com — does it resolve through the system at all?
3. dig @8.8.8.8 example.com — does a public DNS server answer (if yes, the
problem is local/resolved)?
A name resolves to the wrong IP
An entry in /etc/hosts overrides DNS — check it (getent hosts name).
A stale cache: resolvectl flush-caches.
Multiple A records/round-robin — that's normal (load balancing).
resolv.conf gets overwritten after a reboot
Don't edit /etc/resolv.conf directly (it's a symlink to resolved). Configure
DNS in netplan (nameservers:) or /etc/systemd/resolved.conf, then run
sudo netplan apply / systemctl restart systemd-resolved.
Internal names don't resolve, external ones do
There's no search domain or the right DNS for the internal zone. Check
resolvectl status (Search Domains) and add the domain/server in netplan.
dig works, but the application "can't find" the host
dig goes to DNS bypassing NSS. Check with getent hosts/resolvectl
query instead — the cause is in /etc/hosts, nsswitch.conf, or resolved's
cache.