Look Up a Host by namewith dig(1)

The dig(1) program can be used to look up the IP address of a host by specifying the hostname:

% dig example.com

The first time you run dig(1) you may be surprised by the volume of its output,[158] which is composed of comment lines (that begin with a semicolon) and information lines. The first section of output that dig(1) prints might look like this:

% dig example.com
; <<>> DiG 9.2.3 <<>> example.com
;; global options:  printcmd
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 1

This first section is a summary of dig(1)’s command line and information about how it performed the lookup. The global options line shows the resolver options that were in effect when you ran the command. Here, printcmd means that introductory comment lines and other information will print in addition to the answer. If you wish to restrict dig(1)’s output to just the answer, you can execute it with a +short command-line argument. We demonstrate that argument shortly.

The next section of commentary begins with the “Got answer” line:

;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 19898

Here, the opcode is QUERY, which means a simple lookup was performed. The status is NOERROR, which means the lookup was successful, and the id shows the ID of the dig(1) query itself.

The last section of introductory commentary produced by dig(1) is a summary of what it found:

;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 2

The flags are the ...

Get sendmail, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.