Home·Terminal commands

dig

Networking

Usage

dig [@server] <name> [type]

Asks a DNS server directly and shows the records as they come back; it bypasses /etc/hosts and the system cache, so the answer can differ from what the browser sees, and some distributions need dnsutils or bind-utils installed first.

Common flags

FlagMeaning
+shortJust the answer, one record per line.
@1.1.1.1Ask a specific resolver instead of the system one.
A / AAAA / MX / TXT / NS / CNAMEThe record type goes last, with no dash.
+noall +answerTrim the output to the answer section only.
-x <ip>Reverse lookup, address to name.
+traceWalk down from the root servers, which shows where a delegation breaks.
+ttlunitsPrint TTLs as 1h30m instead of raw seconds.

Examples

dig +short example.com

The A records, nothing else.

dig @1.1.1.1 example.com MX +noall +answer

Mail records straight from a public resolver.

dig -x 8.8.8.8 +short

Which name that address claims.

When a connection fails, these narrow down how far it got — name not resolving, no route, or a blocked port.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does dig do?

Asks a DNS server directly and shows the records as they come back; it bypasses /etc/hosts and the system cache, so the answer can differ from what the browser sees, and some distributions need dnsutils or bind-utils installed first.

Q. How do I type it?

dig [@server] <name> [type] — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

7 are listed here; the full set is in man dig. This command sits under Networking.

Related commands

man page: man dig