Network

The dig command

Queries DNS servers and prints the answer: IP addresses, records and timings.

Syntax

dig [@servidor] [nombre] [tipo] [+opciones]Try it in the terminal →

Most useful options

+shortOnly the value of the answer, without headers. Ideal for scripts.
@servidorAsks that DNS server instead of the one configured on your machine, such as 1.1.1.1.
-t <tipo>Record type: A, AAAA, MX, NS, TXT, CNAME... If you do not give one, it asks for A.
-x <ip>Reverse lookup: from an IP address to the name it has (PTR record).
+traceFollows the delegation from the root servers and shows the answer from each one.
+tcpUses TCP instead of UDP for the query.

Copy-ready examples

$ dig miguelacm.es +shortonly the domain's IP, with no headers.

Example output

203.0.113.10
$ dig miguelacm.es MX +shortonly the mail servers, with their priority.

Example output

10 mx1.example.net.
$ dig @1.1.1.1 miguelacm.esfull answer, asking a specific DNS server for the domain.
$ dig -x 203.0.113.10 +shortreverse lookup: which name that IP has.

Example output

web01.example.net.
$ dig +trace miguelacm.eswalks the chain from the root down to the domain's servers, to see where a resolution breaks.

You can try them in the browser terminal: it does not touch your computer.

Typical mistakes

  • Without +short you see the full answer. The ANSWER section is the one that matters; the rest is headers and timings.
  • Answers can come from cache: after changing a record, wait for the TTL or compare with a public server such as 1.1.1.1.
  • Without @server, dig uses your machine's DNS, so a strange result may come from your network and not from the domain.
  • dig is not always installed: it usually ships in a separate package, together with the BIND utilities.

Related commands

FAQ

Why does dig show NXDOMAIN?

The name does not exist in the DNS server you asked: it may be misspelled, or the domain may not be registered. Try another server before assuming the domain is down.

How do I check whether a DNS change has spread?

Query several servers with @ and compare. If each one answers differently, cache or a pending TTL is still in play.

What does the TTL column mean?

The number of seconds a resolver may cache the answer before asking again. With +noall +answer you see only the answer section.

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course