Let’s DIG Deeper With 20 Most Useful DIG Examples for DNS and Network Administrators

Let’s DIG Deeper With 20 Most Useful DIG Examples for DNS and Network Administrators

D.I.G which stands for “Domain Information Groper” is a powerful tool available on most Unix/Linux systems and very helpful to DNS or Network Administrator in their daily routines which involve maintaining DNS servers and troubleshooting DNS issues. DIG can also be installed on Windows by downloading BIND and installing the BIND tools or Cygwin. But before we dig in, let’s first familiarize ourselves with the anatomy of a dig query. To understand this better, we shall break it down into three categories:

  1. DNS Operation Codes
  2. DNS Flags
  3. DNS Response Codes

Let’s try and understand what each of the above three categories is about!

1. QUERY (Standard Query – OpCode 0): This is the most common operation code, used for standard DNS queries where the client requests the resolution of a domain name into its IP address.

2. IQUERY (Inverse Query – OpCode 1): This is used for inverse DNS lookups, where the client provides an IP address and requests the corresponding domain name. However, this OpCode is now considered obsolete.

3. STATUS (Server Status Request – OpCode 2): This code is used to query the server for its status.

4. NOTIFY (OpCode 4): Used by a master server to notify a slave server that the zone has been updated and a zone transfer needs to be initiated.

5. UPDATE (Dynamic Update – OpCode 5): This is used for dynamically updating the DNS records in a zone.

1. QR (Query/Response): A 1-bit field that specifies whether the message is a query (0) or a response (1).

2. Opcode: A 4-bit field that specifies the kind of query in a DNS message. It indicates the desired action, such as a standard query (0) or a dynamic update (5).

3. AA (Authoritative Answer): A 1-bit field that indicates whether the responding DNS server is an authority for the domain name in question (1) or not (0).

4. TC (Truncation): A 1-bit field that specifies whether the message was truncated (1) because it was longer than the allowed length of 512 bytes when using UDP.

5. RD (Recursion Desired): A 1-bit field set by the client to indicate that recursive query resolution is desired (1).

6. RA (Recursion Available): A 1-bit field set by the server to indicate that it can do recursive queries (1).

7. Z (Reserved): A 3-bit field reserved for future use. Must be zero in all queries and responses.

8. RCODE (Response Code): A 4-bit field that indicates the outcome of the query, such as no error (0), format error (1), or server failure (2).

1. NOERROR (RCODE:0): Indicates that the DNS query completed successfully. For example, if you query the DNS for the IP address of www.techjunction.co and it exists, you will receive a NOERROR response.

2. FORMERR (RCODE:1): Signifies a DNS Query Format Error. This occurs when the DNS server cannot understand the query due to a problem with the way it is formatted. An example would be if the query message is corrupted or improperly constructed.

3. SERVFAIL (RCODE:2): Server failed to complete the DNS request. This can happen if the DNS server is experiencing issues or if there is a problem with the network.

4. NXDOMAIN (RCODE:3): Domain name does not exist. If you try to resolve a domain name that is not registered, you will get an NXDOMAIN response.

5. NOTIMP (RCODE:4): Function not implemented. This response is given when the DNS server does not support the requested operation, such as an unsupported query type.

6. REFUSED (RCODE:5): The server refused to answer for the query. This can be due to policy reasons, like if the requested domain is blacklisted.

7. YXDOMAIN (RCODE:6): Name that should not exist, does exist. This is used in dynamic update messages.

8. XRRSET (RCODE:7): RRset that should not exist, does exist. Also used in dynamic update messages.

9. NOTAUTH (RCODE:8): Server not authoritative for the zone. This means the server is not responsible for the domain queried.

10. NOTZONE (RCODE:9): Name not in zone. This indicates that the query name is not within the zone the server is authoritative for. For example, if you make a DNS query for anothertechjunction.co, and there is no such domain registered, the DNS server will return an NXDOMAIN response code, indicating that the domain does not exist. These response codes are essential for diagnosing issues with DNS queries and understanding the status of the responses received. The Internet Assigned Numbers Authority (IANA) maintains the full list of DNS response codes for reference.

Now that we fully understand the anatomy of a DIG query, let’s dig in with these 20 most useful dig examples for DNS Administrators and Network Administrators.

1.) Retrieve A records (IP addresses) for a domain:
dig <domain>

# dig techjunction.co

2.) Retrieve specific record types for a domain (e.g. A, AAAA, MX, NS, CNAME, TXT, SOA):
dig <domain> <record_type>

# dig techjunction.co ns

3.) Perform reverse lookup on IP address (PTR records):
dig -x <ipaddress>

# dig -x 50.116.84.38

4.) Retrieve any records for a domain:
dig <domain> ANY

# dig techjunction.co any

5.) Send DNS requests to a particular DNS server:
dig @<hostname-or-IP> <domain>

# dig @1.1.1.1 techjunction.co

6.) Print the SOA (Start Of Authority) records from each NS server in the domain:
dig <domain> +nssearch

# dig techjunction.co +nssearch

7.) Perform DNS Zone Transfer:
dig <domain> AXFR

# dig techjunction.co axfr

8.) Set/change the query timeout (default it 5 seconds, minimum is 1 second):
dig <domain> +time=<timeInSec>

# dig techjunction.co +time=10

9.) Set/change the number of retries (default is 2, doesn’t include the initial query):
dig <domain> +retry=<number>

# dig techjunction.co +retry=5

10.) Set/change the source ip and port (must be one of the host’s network interfaces):
dig -b “<srcIp>#<srcPort>” <domain>

# dig -b "197.231.x.x#8000" techjunction.co

11.) Use TCP instead of UDP:
dig <domain> [+tcp|+vc]

# dig techjunction.co +tcp
# dig techjunction.co +v

12.) Disable recursion:
dig <domain> +norecurse

# dig techjunction.co +norecurse

Notice the “rd” for “recursion desired” flag has been removed in the query below:

13.) Trace/follow the DNS resolution (see requests to each intermediate DNS server):
dig <domain> +trace
This command will trace the DNS resolution, starting at root, through each intermediary server

# dig techjunction.co +trace

14.) Best effort to display malformed answers (not displayed by default):
dig <domain> +besteffort

# dig techjunction.co +besteffort

15.) Multiple domains lookup:
dig <domain1> <domain2> <domain3>

# dig techjunction.co cool.com

 16.) Multiple domains lookup from a file (one domain per line):
dig -f </path/to/file>

# dig -f /tmp/mydomains.txt

 17.) Print records like the SOA records in a verbose multi-line format with human-readable comments:
dig <domain> +multiline

# dig techjunction.co +multiline

18.) Display additional comments and multi-line (very useful for DNSSEC!)
dig <domain> +comments +multi

# dig techjunction.co +comments +multi

19.) Don’t display comments
dig <domain> +nocomments

# dig techjunction.co +nocomments

20.) Retrieve only the short answer (for instance just the IP address)
dig <domain> A +short

# dig techjunction.co A +short

Joshua Makuru PP Linked

About the Author

Joshua Makuru Nomwesigwa is a seasoned Telecommunications Engineer with vast experience in IP Technologies; he eats, drinks, and dreams IP packets. He is a passionate evangelist of the forth industrial revolution (4IR) a.k.a Industry 4.0 and all the technologies that it brings; 5G, Cloud Computing, BigData, Artificial Intelligence (AI), Machine Learning (ML), Internet of Things (IoT), Quantum Computing, etc. Basically, anything techie because a normal life is boring.

Spread the word: