Using dig to query a DNS server

Sun, 08/26/2012 - 19:07 -- jamie

DNS (Domain Name System) translates from a domain name to an IP address.

This usually happens behind the scenes - if you type a domain name like into your web browser, your webrowser looks up the domain name, translates it into an IP address, queries the server responding to the IP address and then displays the web page - all the while, the actual IP address is hidden from you.

Sometimes, it's useful to manually do a lookup, particularly when you are debugging a problem that might be the result of a lookup failure.

You will need to have binutils installed to run this command. Start by seeing if binutils is installed with:

dpkg -l binutils

If it is not installed, install it:

sudo apt-get install binutils

Once installed, you should have access to the dig command. Try looking up a domain name with:


By default, dig will use the caching DNS servers that your computer is configured to use. If you are curious to see what caching DNS server is being used, type:

cat /etc/resolv.conf

Once you query a domain name, that domain name will be in your caching DNS server's cache for as long as the "time to live" record specifies.

For example:

0 jamie@animal:~$ dig
; <<>> DiG 9.8.1-P1 <<>>
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 15700
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;			IN	A
;; Query time: 0 msec
;; WHEN: Sun Aug 26 19:04:06 2012
;; MSG SIZE  rcvd: 46
0 jamie@animal:~$ 

In the example above, the time to live is "563" - which means 563 seconds. You will have to wait 563 seconds for it to expire from the cache, at which point, your caching DNS server will query the authoritative server for the results.

Supposed I changed the DNS record with the authoritative server (e.g. via the May First/People Link control panel), and I want to see if that change was properly made, but I don't want to wait around for the time to live to expire.

First, find out which servers are the authority for

dig -t ns

Then, using the @ sign, query those servers directly:


Notice that the time to live doesn't change when you query the authoritative name server.