DEV Community

Safal Bhattarai
Safal Bhattarai

Posted on

Linux nslookup Command: 5 Examples Every Developer Should Know

The nslookup (Name Server Lookup) command is a simple tool for querying DNS servers on Linux. It is a quick way to check what a domain resolves to, inspect DNS records, and troubleshoot name resolution problems.

If you read my previous post, Linux dig Command: 5 Examples Every Developer Should Know, you'll notice nslookup does similar work with a shorter, friendlier output.

1. Install nslookup

nslookup ships in the same package as dig. On Debian/Ubuntu:

sudo apt update
sudo apt install dnsutils
Enter fullscreen mode Exit fullscreen mode

2. Find a Domain's IP Address

nslookup google.com
Enter fullscreen mode Exit fullscreen mode

The output shows the DNS server that answered your query, followed by the IP addresses for the domain.

Note: If you see Non-authoritative answer, it means the response came from a cache (such as your ISP's or a public resolver) rather than directly from the domain's own name servers. This is normal.

3. Check Specific DNS Records

Use the -type option to choose a record type:

nslookup -type=A google.com
nslookup -type=AAAA google.com
nslookup -type=MX google.com
nslookup -type=NS google.com
nslookup -type=TXT google.com
Enter fullscreen mode Exit fullscreen mode
Record Purpose
A IPv4 address
AAAA IPv6 address
MX Mail servers
NS Name servers
TXT Text records (SPF, domain verification, etc.)

4. Query a Specific DNS Server

Add the DNS server address at the end of the command:

nslookup google.com 8.8.8.8
Enter fullscreen mode Exit fullscreen mode

This asks Google's public DNS resolver instead of your system default. It's useful for checking whether a problem is caused by your local resolver or by the domain's DNS records.

5. Reverse DNS Lookup

Give nslookup an IP address to find the hostname linked to it:

nslookup 8.8.8.8
Enter fullscreen mode Exit fullscreen mode

Reverse lookups are handy when checking server logs or confirming that an IP address maps back to the expected hostname.

Bonus: Interactive Mode

Run nslookup with no arguments to enter interactive mode:

nslookup
> set type=MX
> google.com
> server 1.1.1.1
> google.com
> exit
Enter fullscreen mode Exit fullscreen mode

This lets you run several queries in a row and change the record type or DNS server between them.

dig vs nslookup

dig nslookup
Output Detailed, script-friendly Short and simple
Trace resolution Yes (+trace) No
Best for In-depth DNS debugging Quick lookups

Conclusion

The nslookup command is a fast way to check DNS records and confirm how a domain resolves. Use it for quick checks, and reach for dig when you need more detail.

Next: Linux ping Command: Simple Examples.


About Me

I'm Safal Bhattarai, a Tech Lead, Full Stack Developer, and DevOps Engineer.

๐ŸŒ Website ยท ๐Ÿ’ป GitHub

Top comments (0)