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:

dig my.domain.com

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 my.domain.com @192.168.1.1

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

dig my.domain.com @ns1.mydomain.com

Example Output

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

; <<>> DiG 9.18.18-0ubuntu0.22.04.2-Ubuntu <<>> blog.programster.org @ns1.digitalocean.com
;; 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

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
;; QUESTION SECTION:
;blog.programster.org.      IN  A

;; ANSWER SECTION:
blog.programster.org.   300 IN  A   95.216.255.58

;; Query time: 11 msec
;; SERVER: 173.245.58.51#53(ns1.digitalocean.com) (UDP)
;; WHEN: Tue Apr 02 19:15:15 BST 2024
;; MSG SIZE  rcvd: 65

It may be important to know that the part with ;; Server: xxx.xxx.xxx.xxx 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: 10th September 2024
First published: 16th August 2018

This blog is created by Stuart Page

I'm a freelance web developer and technology consultant based in Surrey, UK, with over 10 years experience in web development, DevOps, Linux Administration, and IT solutions.

Need support with your infrastructure or web services?

Get in touch