Skip to content

Linux Foundations / Follow traffic and find the fault ยท Step 34 of 46

Lesson: DNS ToolsSwitch
โ† Linux Foundations

Network operations

DNS Tools

Troubleshoot name resolution with dig, host, nslookup, getent and resolvectl.

When a name does not resolve, you need to know whether the problem is your machine, your resolver or the domain itself. These tools tell you.

Installing them

dig, host and nslookup come from BIND's utilities. Install dnsutils or bind9-dnsutils on Debian and Ubuntu, or bind-utils on Fedora and RHEL.

dig

dig gives the most detail. The basic form is dig name type:

$ dig example.com A
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 4242
;; ANSWER SECTION:
example.com.    300    IN    A    192.0.2.80
;; SERVER: 192.168.1.1#53(192.168.1.1)

This output is shortened and uses a placeholder address. Read three things: the status, the answer section and which SERVER replied.

Useful variations:

$ dig +short example.com AAAA
$ dig @192.168.1.1 example.com MX
$ dig -x 192.0.2.80

+short prints only the data, @server picks which server to ask, and -x does a reverse (PTR) lookup.

Reading the status

  • NOERROR: the query worked. The answer can still be empty if the name has no record of that type.
  • NXDOMAIN: the name does not exist.
  • SERVFAIL: the server could not complete the lookup.
  • REFUSED: the server will not answer you.

host and nslookup

host gives short, readable answers:

$ host example.com
example.com has address 192.0.2.80

nslookup is also common and exists on Windows:

$ nslookup example.com 192.168.1.1

The second argument is the server to ask.

getent and resolvectl

The tools above talk to DNS servers. getent hosts name instead uses the system lookup, including /etc/hosts. If dig succeeds but your application fails, compare with getent.

On systems running systemd-resolved:

$ resolvectl status
$ resolvectl query example.com

The first shows the DNS servers in use for each link. The second resolves a name through the service.

A simple method: run getent, then dig, then dig against a different resolver. Where the answers first differ is where to look. For the wider network side, try the networking and SSH lab.

Try it

  1. Run dig +short example.com and host example.com.
  2. Look up a made-up name under .invalid with dig and find the status.
  3. Compare dig and getent hosts for localhost and explain any difference.

Check your understanding

DNS Tools

All 5 sections ยท no timer

Unlimited retries

Questions from every section are combined into one assessment. Answer them all correctly to complete the article.

Your completion saves in this browser. Sign in to sync it to your account.