Cheat sheet
dig cheat sheet: DNS lookups
DNS lookups from the command line: dig first, then nslookup, getent and delv.
dig
Asks a DNS server a question and prints the full answer: status, records, who answered and how long it took.
dig +short webServer.lab- Prints only the address webServer.lab resolves to.
dig webServer.lab- Asks the configured resolver and prints the whole answer, including which server replied.
dig @10.0.1.2 webServer.lab- Asks the server at 10.0.1.2 directly, skipping /etc/resolv.conf.
dig AAAA webServer.lab +short- Asks for the name's IPv6 address.
dig -x 10.0.2.10 +short- Asks which name belongs to the address 10.0.2.10.
dig @10.0.0.53 www.example.lab +norecurse- Asks one server without recursion, to see the referral it gives.
dig +noall +answer webServer.lab- Prints only the answer lines, with each record's TTL and type.
dig MX example.com +short- Lists the domain's mail servers with their preference, lowest first to try.
nslookup
The nslookup command asks a DNS server for the address behind a name and prints which server answered.
nslookup webServer.lab- Asks the configured DNS server for webServer.lab's address.
nslookup webServer.lab 10.0.1.2- Asks the server at 10.0.1.2 directly, skipping /etc/resolv.conf.
nslookup -type=a webServer.lab- Asks for the IPv4 address alone.
nslookup -type=mx example.lab- Asks which mail servers take the domain's mail.
getent hosts
The getent command resolves a name the way programs do, /etc/hosts first; /etc/resolv.conf says where names come from.
getent hosts webServer.lab- Resolves webServer.lab the way programs do, hosts file included.
cat /etc/resolv.conf- Shows which DNS servers this device asks, and its search domains.
cat /etc/hosts- Shows names pinned to addresses on this device, which win over DNS.
echo 'nameserver 10.0.1.2' > /etc/resolv.conf- Makes 10.0.1.2 this device's only DNS server.
delv
Looks a name up and checks its DNSSEC signatures itself, from a trust anchor, instead of trusting a resolver's ad flag.
delv www.example.lab- Looks the name up and says whether its signatures check out from the root down.
delv +vtrace www.example.lab 2>&1 | grep -E 'verify|validated'- Shows the keys it checked, zone by zone, and the verdict.
delv www.legacy.lab- Shows an unsigned zone's answer as unsigned, not as a failure.