Razzi's guide to dig


UPDATE: host is way better, use that:

$ host razzi.abuissa.net
razzi.abuissa.net is an alias for pages.sr.ht.
pages.sr.ht has address

dig is a command line dns utility. Its output is hard to parse but the alternatives are no better.1

Here’s the basic usage:

$ dig razzi.abuissa.net

; <<>> DiG 9.18.12-1ubuntu1.1-Ubuntu <<>> razzi.abuissa.net
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 33156
;; flags: qr rd ad; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0
;; WARNING: recursion requested but not available

;razzi.abuissa.net.             IN      A

razzi.abuissa.net.      0       IN      CNAME   pages.sr.ht.
pages.sr.ht.            0       IN      A

;; Query time: 0 msec
;; WHEN: Wed Sep 20 01:00:52 CDT 2023
;; MSG SIZE  rcvd: 104

Wow that’s a lot of output! The only part I really care about is the answer section.

The lines you’ll want to be scanning for are:

razzi.abuissa.net.      0       IN      CNAME   pages.sr.ht.
pages.sr.ht.            0       IN      A

Confusingly, queries with no results omit the answer section entirely:

$ dig some.nonexistentdomain

; <<>> DiG 9.18.12-1ubuntu1.1-Ubuntu <<>> some.nonexistentdomain
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 59662
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1

; EDNS: version: 0, flags:; udp: 512
;some.nonexistentdomain.                IN      A

.                       3600    IN      SOA     a.root-servers.net. nstld.verisign-grs.com. 2023092000 1800 900 604800 86400

;; Query time: 70 msec
;; WHEN: Wed Sep 20 01:10:01 CDT 2023
;; MSG SIZE  rcvd: 126

If you take the time to read from the top, you’ll see ANSWER: 0. So you can scan for that when you make a query.

As an alternative to reading through that whole mess, you can use the +short option to get just the answer:

$ dig +short razzi.abuissa.net
$ dig +short some.nonexistentdomain

In that second example above, there’s no answer, so there’s no output.

usage with vimpager

Helpfully, the excellent vim editor knows how to interpret dig output:

$ dig razzi.abuissa.net > dig.txt
$ vim dig.txt
(shows colorized output)

We can use vimcat to colorize the output directly to stdout:

$ dig razzi.abuissa.net | vimcat
; <<>> DiG 9.18.12-1ubuntu1.2-Ubuntu <<>> razzi.abuissa.net
;; global options: +cmd
# ...
# I don't have syntax highlighting on here but it is colorized!

depends on

source code


(dig is part of the BIND dns suite.)

  1. drill has the same output format. dog, though it looks cool, is unfortunately unmaintained. nslookup doesn’t show CNAMEs by default, though you can get it from nslookup -q=cname