How to Use the Dig Command [With Examples]

dig is the Linux command-line tool used to look up the DNS records for a host. This tutorial explains how to use this command and includes handy examples.

DNS records provide information to your computer about a host’s IP address on a network, email configuration, or other text data that can be associated with the host.

DNS records provide the street directory for the internet. When you access a website, your computer looks up the DNS record associated with the website’s domain to get the IP address of the server hosting it on the internet, so that it can then be accessed.

dig will query these records based on your input and return relevant information.



Note that:

  • SERVER is the address of the DNS server you wish to query – it can be excluded if you want to use the DNS server used on your computer/local network
  • OPTIONS are options that can be passed to dig to change its default behavior
  • NAME is the name of the resource you want to look up – usually a domain name – for example,
dig Command Option
-4 Use IPv4 Only
-6 Use IPv6 Only
-t The type of record to query
-x Simple reverse lookup

dig has a lot of options depending on the type of query you want to make. We’ll cover the most common uses below, but for advanced usage, you can always read the user manual by running:

man dig


Let’s take a look at the most basic usage scenario – running a query for a domain name for an internet website:


Which outputs:

; <<>> DiG 9.10.6 <<>>
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 48089
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

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


;; Query time: 29 msec
;; WHEN: Sat Dec 19 23:19:10 GMT 2020
;; MSG SIZE  rcvd: 59

To keep from getting bogged down in details, you can ignore the first two blocks of text – these are just information on dig itself, followed by details of the query sent.

The ANSWER SECTION shows us the A record for – the IP address of the server associated with that domain name.

The final block of text in the results tells us about the statistics for the query – where the results came from (the DNS Server) and how long it took.

To exclude the additional information and show only the answer section, add the +short option

dig +short

Querying Different Types of DNS Records with the Dig Command

A Record

The IP Address of the host, commonly used to look up web servers:

dig A +short

TXT Records

Text records, used for notes, descriptions, verification codes, other non-standardized data:

dig TXT +short

MX Records

Mail server information:

dig MX +short

NS Records

Details of the nameserver which is supplying the records:

dig NS +short


Get all available records:

dig ANY


dig comes into its own when you’re troubleshooting network issues. It provides an authoritative answer to exactly what information your computer is using to access a network resource, taking out the guesswork.

If you’re running online services, you can use dig to confirm that your DNS configuration has been properly applied by your web host and that everything on your domain is pointing to the right server.

If you’re taking a dive into computer networking, check out our other articles for more useful tips.

Photo of author
I'm Brad, and I'm nearing 20 years of experience with Linux. I've worked in just about every IT role there is before taking the leap into software development. Currently, I'm building desktop and web-based solutions with NodeJS and PHP hosted on Linux infrastructure. Visit my blog or find me on Twitter to see what I'm up to.

Leave a Comment