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.
dig SERVER OPTIONS NAME
- 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, linuxscrew.com
|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:
Let’s take a look at the most basic usage scenario – running a query for a domain name for an internet website:
; <<>> DiG 9.10.6 <<>> linuxscrew.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 48089 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 1232 ;; QUESTION SECTION: ;linuxscrew.com. IN A ;; ANSWER SECTION: linuxscrew.com. 300 IN A 220.127.116.11 ;; Query time: 29 msec ;; SERVER: 18.104.22.168#53(22.214.171.124) ;; 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 linuxscrew.com – 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 linuxscrew.com
Querying Different Types of DNS Records with the Dig Command
The IP Address of the host, commonly used to look up web servers:
dig A +short linuxscrew.com
Text records, used for notes, descriptions, verification codes, other non-standardized data:
dig TXT +short linuxscrew.com
Mail server information:
dig MX +short linuxscrew.com
Details of the nameserver which is supplying the records:
dig NS +short linuxscrew.com
Get all available records:
dig ANY linuxscrew.com
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.