Hacker News new | ask | show | jobs
by inamberclad 1181 days ago
dig has the worst output I've ever seen in a CLI tool. Fantastically useful when I've bothered to learn it, but it's just not intuitive. I always forget what everything means. What am I looking at here? The _lack_ of an answer section?
5 comments

It's very verbose by default, but that's when/why you use it. If you just want to know why something doesn't work, you use ping.

    $ ping nxdomain.example.com
    ping: nxdomain.example.com: Name or service not known

    $ ping example.com
    PING example.com(2606:2800:220:1:248:1893:25c8:1946 (2606:2800:220:1:248:1893:25c8:1946)) 56 data bytes
    64 bytes from 2606:2800:220:1:248:1893:25c8:1946 (2606:2800:220:1:248:1893:25c8:1946): icmp_seq=1 ttl=52 time=93.2 ms
If you want a short summary, you use host:

    $ host nxdomain.example.com
    Host nxdomain.example.com not found: 3(NXDOMAIN)


    $ host example.com
    example.com has address 93.184.216.34
    example.com has IPv6 address 2606:2800:220:1:248:1893:25c8:1946
    example.com mail is handled by 0 .
or nslookup (from the same bind9-dnsutils package as dig):

    $ nslookup nxdomain.example.com
    Server:  127.0.0.53
    Address: 127.0.0.53#53
    
    ** server can't find nxdomain.example.com: NXDOMAIN

    $ nslookup example.com
    Server:  127.0.0.53
    Address: 127.0.0.53#53
    
    Non-authoritative answer:
    Name: example.com
    Address: 93.184.216.34
    Name: example.com
    Address: 2606:2800:220:1:248:1893:25c8:1946

If you want to debug DNS, with all the raw data, then you use dig.
dig +short enters the room.
Alternatively, use dog (https://github.com/ogham/dog)

> dog A readlang.com

A readlang.com. 1h57m12s 139.144.234.197

> dog A someinvalidserver.com

Status: NXDomain

Yes, it's horrible. It helps if you know the actual syntax used in zone files, and yes, it's the lack of an answer section.

Alternatively use the short format as suggested by another comment:

    $ dig a www.readlang.com +short
    readlang.com.
    139.144.234.197
Although now it's a bit too short and you can't see the record types (CNAME, A). Sigh.
When I dig my personal domain name, I get 19 lines of output of which 1 comes from the zone file and contains the actual answer. The rest is mystery meat.

I mean, sure I can decipher that "rcvd" stands for "received" but if I have my timeline correct there never was a time when such character count mattered and dig existed.

+short is your friend.
But why can't it be --short (or --quiet) like every other tool, so that I then have a chance of being able to remember it the 2-3 times/year I need it?
Out of curiosity I asked ChatGPT what the output means and this is what it responded :) Maybe this helps you!

This output is the result of using the dig command to query the DNS (Domain Name System) for an A (Address) record associated with the domain name "www.readlang.com". Here's a breakdown of the output:

; <<>> DiG 9.10.6 <<>> a www.readlang.com: This line shows the version of dig being used (9.10.6) and the command executed (dig a www.readlang.com). The "a" argument is asking for the IPv4 address associated with the domain name.

;; global options: +cmd: This line displays global options for the dig command. "+cmd" is a default option that includes the initial command line in the output.

;; Got answer:: This line indicates that the DNS server has provided an answer to the query.

;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 65131: This line shows details about the response header. "opcode: QUERY" means it's a standard query, "status: NXDOMAIN" indicates that the domain name does not exist (non-existent domain), and "id: 65131" is a unique identifier for this query.

;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1: This line provides information about the response flags and the number of entries in each section of the response. "qr" means the response is a query response, "rd" indicates recursion was desired, and "ra" means recursion is available. The number of entries in the QUERY, ANSWER, AUTHORITY, and ADDITIONAL sections are 1, 0, 0, and 1, respectively.

;; OPT PSEUDOSECTION: and ; EDNS: version: 0, flags:; udp: 1280: This part shows information about the Extension Mechanisms for DNS (EDNS). The version is 0, and the UDP payload size is 1280 bytes.

;; QUESTION SECTION: and ;www.readlang.com. IN A: This part displays the question section of the query, which is asking for the A record (IPv4 address) associated with "www.readlang.com".

;; Query time: 62 msec: This line shows that the query took 62 milliseconds to complete.

;; SERVER: 2406:3400:41e:5a80::1#53(2406:3400:41e:5a80::1): This line displays the IPv6 address and port number of the DNS server that responded to the query.

;; WHEN: Fri Mar 24 10:06:36 AEST 2023: This line indicates the date and time when the query was executed.

;; MSG SIZE rcvd: 45: This line shows that the total size of the message received was 45 bytes.

The main takeaway from this output is that the domain name "www.readlang.com" does not have an associated IPv4 address (A record) in the DNS, as indicated by the "status: NXDOMAIN" and "ANSWER: 0" parts.