· updated
Retrieving DNS Information with dig
What each section of dig's output means, how to print only the part you need, how to ask a specific DNS server, and how +trace follows a lookup down from the root.
dig (domain information groper) is the standard tool for querying DNS. Running it with just a domain name prints this:
dig tetsuya.dev
; <<>> DiG 9.10.6 <<>> tetsuya.dev
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 3259
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1452
;; QUESTION SECTION:
;tetsuya.dev. IN A
;; ANSWER SECTION:
tetsuya.dev. 3596 IN A 104.198.14.52
;; Query time: 94 msec
;; SERVER: 1.1.1.1#53(1.1.1.1)
;; WHEN: Tue Jun 16 22:42:00 JST 2020
;; MSG SIZE rcvd: 67
The next four options each turn one section on, and their +no forms turn it off. +noall turns every section off, so +noall followed by one of them prints only that section. Options apply left to right, so the order matters.
+cmd
Prints the dig version and the global options. Useful when you paste output into notes or a bug report, because it records exactly which version and options produced it.
dig +noall +cmd tetsuya.dev
; <<>> DiG 9.10.6 <<>> +noall +cmd tetsuya.dev
;; global options: +cmd
+ques[tion]
Prints only the question section, which shows what was asked: the domain name, the class (IN, for Internet), and the record type. The type is A if you don’t give one.
dig +noall +ques tetsuya.dev
;tetsuya.dev. IN A
+ans[wer]
Prints only the answer section: the records the server returned, each with its TTL (time to live, in seconds), class, type, and value.
dig +noall +answer tetsuya.dev
tetsuya.dev. 2976 IN A 104.198.14.52
+short
Prints only the values from the answer. Handy in scripts.
dig +short tetsuya.dev
104.198.14.52
+sta[ts]
Prints statistics about the query: how long it took, which DNS server answered, when the query ran, and the size of the response.
dig +noall +stats tetsuya.dev
;; Query time: 94 msec
;; SERVER: 1.1.1.1#53(1.1.1.1)
;; WHEN: Tue Jun 16 22:42:00 JST 2020
;; MSG SIZE rcvd: 67
Query type {A|AAAA|MX|TXT|CNAME|NS}
Add a record type to query it instead of A. Common types:
A: IPv4 addressesAAAA: IPv6 addressesMX: mail serversTXT: free-form text, often used for domain verificationCNAME: an alias for another nameNS: the domain’s name servers
dig +short MX tetsuya.dev
5 gmr-smtp-in.l.google.com.
10 alt1.gmr-smtp-in.l.google.com.
20 alt2.gmr-smtp-in.l.google.com.
30 alt3.gmr-smtp-in.l.google.com.
40 alt4.gmr-smtp-in.l.google.com.
The number before each mail server is its preference. Senders try the lowest number first.
+trace
Normally dig asks a resolver, and the resolver does the lookup. With +trace, dig does the lookup itself and shows the answer from each server along the way:
- It gets the list of root servers from the resolver (1.1.1.1 here).
- A root server (
l.root-servers.net) refers it to the name servers for.dev. - A
.devname server (ns-tld1.charlestonroadregistry.com) refers it to the name servers fortetsuya.dev. - One of those (
ns-cloud-a4.googledomains.com) returns theArecord.
dig +trace tetsuya.dev
. 511067 IN NS a.root-servers.net.
. 511067 IN NS b.root-servers.net.
. 511067 IN NS c.root-servers.net.
. 511067 IN NS d.root-servers.net.
. 511067 IN NS e.root-servers.net.
. 511067 IN NS f.root-servers.net.
. 511067 IN NS g.root-servers.net.
. 511067 IN NS h.root-servers.net.
. 511067 IN NS i.root-servers.net.
. 511067 IN NS j.root-servers.net.
. 511067 IN NS k.root-servers.net.
. 511067 IN NS l.root-servers.net.
. 511067 IN NS m.root-servers.net.
. 511067 IN RRSIG NS 8 0 518400 20200629050000 20200616040000 48903 . aWTFYLbKkhzdBbDxrCPRpJSnEsvwvspYZgJW5NlUmY321DG+yPa6i1z3 YXuNJaBJx0r/XHREn8L9yDJBJWVjmS6VYl7pQLzAXU9B4p889J1PoZoV 8dhG0HNMxda1jfotGCG+xRiLczPLGxMC4fi4wrxYQUj0G2c+dggThwsy T1eRqr74CcU+Ube/RZ09q3li3zg/UxzIVpmbCMmi1gtz93XuhHhcbs3l lVeCo90eaCk7n9Ay9cHOQRKlf7pRwiKLGDznKtI3m+PLpALeMgJzYjsz MKHlvlChy0ss1Utd24u6c9ikeA5dfg6C65f/5eMpqUCF+/KbaEIUoFp/ yzpNew==
;; Received 525 bytes from 1.1.1.1#53(1.1.1.1) in 24 ms
dev. 172800 IN NS ns-tld1.charlestonroadregistry.com.
dev. 172800 IN NS ns-tld2.charlestonroadregistry.com.
dev. 172800 IN NS ns-tld3.charlestonroadregistry.com.
dev. 172800 IN NS ns-tld4.charlestonroadregistry.com.
dev. 172800 IN NS ns-tld5.charlestonroadregistry.com.
dev. 86400 IN DS 60074 8 2 B942E2CE5AEBF62FCA59D05707E6DBB795211D540D8ADBA02E9E89E8 33424785
dev. 86400 IN RRSIG DS 8 1 86400 20200629050000 20200616040000 48903 . kM+Q1cGw0xXAJErILQn9b+xsSrl7cLQk47yU85GNf7+uEvlI4BLRG+L4 1o0cx7FFrveK23dtcMw2Jc+Kha1QPSbw1E6X09XniMDXoezqhF31s0fr yKK3Y2kkxXQpHUVT/NxXWLbJ6ZAi3ctWI6Woh2SbBzb86Ggmma5EDbnG v6rDvOZaEfg/RDO4ccXpSxv9kJNY8mZNlB3hk+gLqlLM2GnWfLC+pnN/ nUJJP15zk8qV+hokk8NXUIC2mmO7QFjbK0+6bIXS2Yq1pvfZYkLumKgb LoWiuaVWcAK3S/rKEKuNW6JGX38DSw2CcROayyvV86zuMhIhKDo7kVj5 zdiaaA==
;; Received 731 bytes from 199.7.83.42#53(l.root-servers.net) in 134 ms
tetsuya.dev. 10800 IN NS ns-cloud-a1.googledomains.com.
tetsuya.dev. 10800 IN NS ns-cloud-a2.googledomains.com.
tetsuya.dev. 10800 IN NS ns-cloud-a3.googledomains.com.
tetsuya.dev. 10800 IN NS ns-cloud-a4.googledomains.com.
0rgudcvqtbf3oand8leokj1f7pk73qiu.dev. 300 IN NSEC3 1 0 1 B7B0891083980E59 0RH185F5P63J2D8I8NKQM07F33LJ80CU NS
0rgudcvqtbf3oand8leokj1f7pk73qiu.dev. 300 IN RRSIG NSEC3 8 2 300 20200704202942 20200612202942 56224 dev. Yxuto/A4xoN8hpN9QlG4TXOAuPJ5+7j4qUT2bV20TfeREGVh1JfkaniU VhMHull4VTW0H6ORR7TKRW+DBXSx/g0nha9JTPYhQHk81R15b4AXm/qm lmbtUofnEFOtY2ndKxtFrPBbEevw+BYH6FC8k1R9PQEEdQE6JU1Ccv/r XRw=
;; Received 406 bytes from 216.239.32.105#53(ns-tld1.charlestonroadregistry.com) in 42 ms
tetsuya.dev. 3600 IN A 104.198.14.52
;; Received 56 bytes from 216.239.38.106#53(ns-cloud-a4.googledomains.com) in 81 ms
It’s the quickest way to see which server in the chain gives a wrong or missing answer.
Asking a different DNS server (@server)
@server sends the query to the server you name instead of your system’s resolver. The SERVER line in the stats shows which server answered.
Cloudflare’s 1.1.1.1
dig @1.1.1.1 +noall +stats tetsuya.dev
;; Query time: 329 msec
;; SERVER: 1.1.1.1#53(1.1.1.1)
;; WHEN: Wed Jun 15 06:40:20 UTC 2022
;; MSG SIZE rcvd: 72
Google Public DNS
dig @8.8.8.8 +noall +stats tetsuya.dev
;; Query time: 92 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Wed Jun 15 06:40:30 UTC 2022
;; MSG SIZE rcvd: 72