How to Use nslookup and dig to Verify and Troubleshoot DNS Configurations?

how to use dig and nslookup

Intro:

DNS (Domain Name System) simplifies the process of accessing websites by users on the internet, mainly by mapping the IP Addresses of the web servers to human-readable names like (google.com).

It has other roles also with other online services (emails, load balancing, etc..), therefore, verifying and troubleshooting DNS settings to ensure it works properly is essential to keep your services up and running.

Tools like nslookup and dig helps with verifying and troubleshooting your dns settings.

What are nslookup and dig?

nslookup: it’s a built-in command tool, supported by most of the operating systems.

dig (Domain Information Groper): advanced DNS lookup tools, it comes with linux and MacOS operating systems, and it can be installed on Windows.

Both tools allow you to query DNS records like MX, TXT, A, AAAA and more.

How to Use dig Command?

Dig is used through a terminal (CMD for windows).

Basic command format:

Replace the [domain] with the domain name you wish to query its records

[record type] can be any DNS record (A, MX, TXT, AAAA, NS, SOA, CNAME, etc…)

Example 1: let’s query google.com for the record type A:

dig command

Example 2: query an MX record type:

Query a specific DNS server:

Example : I will query google.com from cloudflare DNS server (1.1.1.1):

query a specific server with dig

Check reverse DNS lookup:

To resolve an IP address to a domain name:

Example: the IP 172.217.17.46, should resolve to a domain name that belongs to a domain name:

reverse dns lookup with dig

Using Trace option for detailed resolution process:

If you need advanced troubleshooting for DNS process you can use “Trace” option:

Example: Here we can query google.com to trace the process:

trace option with dig

Set Custom Timeout:

If you would like to reduce or extend the timeout, you can set the timeout in seconds.

Example: Here I adjust the timeout for the below query to 5 Seconds:

timeout with dig

Increase the query number of attempts:

With “retry” option, you can increase the number of attempts of the query:

Example: Here I will increase the number of tries to 3, with a wrong domain name so we can check the number of attempts:

Export results to text file:

You can save the results of a query in a text file using:

Example: Let’s save the results of this query to a file:

The file will contain the results as below:

export dig results to a file

Query Bulk DNS with a File:

You can batch a DNS query from a file contains the domains (one domain per line):

Example: Here I have a file contains 4 domains, I will batch query the domains:

Now, let see the results:

batch dns lookup with dig

Combining multiple options together:

We can mix options together to get the desired output:

Example 1: batch query the domains file, then save the results to another file:

Example 2: increase the number of attempts and trace the dns process:

Example 3: query a domain from a specific name server with a timeout of 10 seconds:

How to Use nslookup Command?

Basic Query:

Nslookup uses the below command for basic A record query:

Example: querying google.com:

nslookup

Query a specific DNS record:

You can specify which DNS record you want to query (A, AAAA, TXT, MX, SOA, … ):

Example: let’s query a domain for MX record type:

Query a specific name server:

You can specify a name server as below:

Example: let’s specify 8.8.8.8 as a name server:

query a specific dns server with nslookup

Conclusion:

Mastering nslookup and dig helps you verify and troubleshoot DNS configurations effectively. Use dig for detailed queries and advanced troubleshooting, while nslookup is great for quick lookups. With these tools, you can diagnose DNS issues, verify records, and ensure smooth network operations.

For easier lookup and bulk query, you can use this Bulk DNS Lookup Tool.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *