Network and remote access

Command dig

Query DNS records

Linux · Bash examples · commands run on the selected server

When to use dig

Use dig to inspect DNS records and compare resolvers. Query a specific record type and server when troubleshooting; DNS caching, delegation and split-horizon configuration can legitimately produce different answers.

Syntax

dig [@DNS_SERVER] NAME [TYPE]

Square brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.

Common options and arguments

+short
Short answer.
+trace
Trace delegation from root DNS.
@ADDRESS
Select DNS server for the request.

Usage examples

Request IPv4 addresses

dig example.com A

The default resolver is asked for the domain's IPv4 address records.

Check mail records

dig +short example.com MX

Mail-exchange results are displayed in a concise format.

Check a specific DNS server

dig @1.1.1.1 example.com A

A specific public resolver is queried, allowing comparison with the server's configured resolver.

Notes and limitations

  • dig is usually supplied by the dnsutils or bind-utils package.
  • The answer depends on the selected server and its cache. A missing DNS record differs from a missing network response.

Common questions and troubleshooting

Why does dig differ from the address an application uses?

Applications can use local hosts files, caches or other resolution mechanisms. dig queries DNS and does not reproduce every system lookup path.

Does an empty answer always mean DNS is broken?

No. The requested record type may be absent or the response may contain a referral or negative answer. Inspect status and authority information.

Further help

Options vary by version and distribution. Check the installed documentation with this command: man dig.