Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Dig - DNS Querying

Dig is a DNS lookup utility that can be useful for checking your DNS is answering queries correctly.

Install Dig

One can install the dig tool with the following command

sudo apt-get install dnsutils

Query DNS

If you want to query your current default DNS for a hostname, then simply enter the command below:


If you want to query a specific DNS, such as one you just set up, then one needs to specify it like below (substituting the IP):

dig @

Alternatively, you can use a hostname for the nameserver, rather than the IP address, like below:


Example Output

Below is an example of the ouput from such a query:

; <<>> DiG 9.18.18-0ubuntu0.22.04.2-Ubuntu <<>>
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 11332
;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; WARNING: recursion requested but not available

; EDNS: version: 0, flags:; udp: 1232
;      IN  A


;; Query time: 11 msec
;; WHEN: Tue Apr 02 19:15:15 BST 2024
;; MSG SIZE  rcvd: 65

It may be important to know that the part with ;; Server: is the IP address of the DNS server that responded. This is an easy way to figure out which DNS server you are using if you do not know.

Clearing DNS Cache

If you are running Ubuntu 22.04 as I am, you can clear your local DNS cache by running:

sudo resolvectl flush-caches
Last updated: 2nd April 2024
First published: 16th August 2018