The Art of Doing Science and Engineering: Learning to Learn
10% OffNslookup is a useful command line tool for troubleshooting DNS issues and querying DNS records on Linux, Windows, and macOS systems. However, you may encounter the “nslookup command not found” error when trying to run nslookup on your system.
In this comprehensive guide, we’ll cover the reasons for the nslookup not found error and how to fix it on both Linux and Windows machines. We’ll also provide nslookup usage examples so you can quickly resolve DNS issues.
What is nslookup?
Nslookup is a command-line administrative tool for testing and troubleshooting DNS servers and name resolutions. It allows you to:
- Query the IP address for a hostname.
- Find the hostname for an IP address.
- View DNS records like MX, CNAME, TXT, etc.
- Test if a DNS server is reachable.
- Diagnose DNS problems and errors.
The nslookup command line tool is included with most operating systems like Windows, Linux, and macOS. It provides an interactive mode where you can query DNS details or run single queries.
Here are some common examples of using nslookup:
nslookup example.com # Query IP for hostname
nslookup 127.0.0.1 # Reverse lookup hostname for IP
nslookup -type=MX example.com # Check mail records
Now let’s look at why you might get the “nslookup command not found” error when trying to use this handy DNS tool.
Why nslookup Is Not Found on Your System
There are a few possible reasons you may get a “nslookup command not found” error:
1. nslookup is not installed
This is the most common reason. Nslookup may not be installed on your Linux or Windows system by default.
On Linux, it’s usually included in the bind-utils
package. On Windows, it’s a feature that needs to be enabled.
2. nslookup is not in your system PATH
Even if nslookup is installed, your system’s PATH environment variable may not contain the directory where nslookup is installed. So when you run it, the shell can’t locate the executable.
3. You have a typing error in the command
Double-check that you have typed nslookup
correctly and not misspelled it.
4. You’re using an older version of nslookup
Some older Linux/UNIX systems included a very outdated version of nslookup in the bind-utils
package that had limited functionality. Trying to run commands that don’t work in the old version will show “command not found.”
Now let’s look at how to install nslookup and add it to your system PATH to resolve the “command not found” issue.
How to Fix nslookup Command Not Found on Linux
Here are the steps to fix the nslookup not found error on a Linux system:
Step 1 – Install bind-utils Package
The nslookup executable is included in the bind-utils
package on most Linux distributions. To install it:
On Debian/Ubuntu:
sudo apt update
sudo apt install bind-utils
On CentOS/RHEL:
sudo yum update
sudo yum install bind-utils
On Fedora:
sudo dnf update
sudo dnf install bind-utils
This will install nslookup along with other handy DNS tools like dig, host, etc.
Step 2 – Add bind-utils Path to $PATH Variable
Just installing the bind-utils package may not be enough, as your system’s $PATH variable may not contain the path to the nslookup executable.
You can find where nslookup is installed by running:
which nslookup
This will typically output /usr/bin/nslookup
.
To add this path, edit your shell profile script:
For Bash shells:
nano ~/.bash_profile
For Zsh shells:
nano ~/.zshrc
Then add this line to append the bind-utils
path to $PATH:
export PATH=$PATH:/usr/bin
Save and close the file, then reload it:
source ~/.bash_profile
# OR
source ~/.zshrc
The nslookup command should now work when you run it again!
Step 3 – Use absolute Path to nslookup
If adding the path to your $PATH did not work, you can also run nslookup using its full absolute path:
/usr/bin/nslookup example.com
This bypasses any $PATH issues and runs the nslookup executable directly.
And that’s it! The nslookup not found error on Linux should now be resolved.
How to Fix nslookup Not Found on Windows
On Windows machines, nslookup must be enabled as it is not included by default. Here’s how to install and enable it:
Step 1 – Install DNS Server Role
Nslookup is installed as part of the DNS Server server role in Windows. To add this role:
- Open Server Manager
- Click Manage and Add Roles and Features
- Select Role-based or feature-based installation
- On the Server Roles screen, check the box for DNS Server
- Click Next and Install to finish adding this role
This will install all the DNS Server features, including nslookup.
Step 2 – Add DNS Server Tools to Path
Even after installing the DNS role, you still need to add the DNS tools path to your system PATH environment variable.
The DNS tools including nslookup are located in the C:\Windows\System32\dns
folder.
To add this:
- Open Advanced system settings
- Click Environment Variables
- Under System Variables, find the PATH variable and click Edit
- Click New and add
C:\Windows\System32\dns
- Click OK to close and save this change
Now nslookup and other DNS tools will be accessible from any command prompt.
Step 3 – Restart the Command Prompt
For the new PATH changes to take effect, close any open command prompt windows and open a new one.
You should now be able to run nslookup commands successfully!
nslookup example.com
And that covers how to fix the nslookup not found error on both Linux and Windows!
Nslookup Usage and Commands
Now that you’ve installed nslookup, let’s look at some examples of how to use it to query DNS records and troubleshoot problems.
Nslookup has two modes – interactive and non-interactive.
Interactive Mode Usage
Interactive mode allows you to run multiple lookups and change settings. To use it:
# Linux/MacOS
nslookup
# Windows
nslookup -mode=interactive
This will open the > prompt where you can run commands:
> server 8.8.8.8 # Change to Google DNS
> example.com # Lookup IP address
> set type=MX # Switch to MX record lookup
> example.com # Get MX records
> exit # Exit nslookup
Some common interactive commands:
server
– Change the DNS server to queryset type=X
– Sets record type X to lookup (A, AAAA, MX, TXT, etc)ls
– Lists all data from the DNS serverhelp
– Print help infoexit
– Exit nslookup interactive mode
Non-Interactive Mode Usage
Non-interactive mode runs a single query and then exits. Use it like:
# Linux/macOS
nslookup example.com
nslookup -type=MX example.com
# Windows
nslookup example.com
nslookup -query=MX example.com
Non-interactive is useful for quick one-off lookups in scripts or via SSH.
Now let’s look at some examples of how to use nslookup commands to troubleshoot and diagnose different DNS issues.
Nslookup Troubleshooting Examples
Check the DNS IP Address
Use nslookup to check if a DNS server IP is reachable:
nslookup
> server 8.8.8.8
Default server: 8.8.8.8
Address: 8.8.8.8#53
If the IP address is not reachable, you will get an error like “connection timed out.”
Lookup the IP for a Domain
Find the IP address mapped to a domain/hostname:
nslookup example.com
Server: 8.8.8.8
Address: 8.8.8.8#53
Non-authoritative answer:
Name: example.com
Address: 93.184.216.34
If the IP returned is not what you expect, there may be a DNS resolution issue for that domain.
Reverse Lookup a Hostname
Do a reverse DNS lookup to find the hostname for an IP address:
nslookup 93.184.216.34
Server: 8.8.8.8
Address: 8.8.8.8#53
Non-authoritative answer:
34.216.184.93.in-addr.arpa name = example.com
If this shows the wrong hostname, the reverse DNS record (PTR) needs to be updated.
Lookup DNS Record Types
Query other DNS record types like MX, CNAME, TXT, etc:
# MX record
nslookup -type=MX example.com
# CNAME record
nslookup -type=CNAME subdomain.example.com
# TXT record
nslookup -type=TXT example.com
This can help identify issues with mail routing, aliases, or SPF/DKIM text records.
Trace DNS Delegation and Authority
View the full chain of DNS delegation for a domain:
nslookup -type=NS domain.com
This shows the DNS servers that are authoritative for this domain at each level. Useful for troubleshooting delegation issues.
Diagnose Connectivity Issues
If your public DNS queries fail but private IPs work, it indicates a general connectivity issue:
nslookup example.com
;; connection timed out
nslookup 192.168.1.1
Name: 192.168.1.1
Address: 192.168.1.1
Check your network, firewall, VPN, or proxy settings to allow public DNS resolution.
Nslookup is a powerful tool for investigating DNS problems. Use these examples and commands to quickly diagnose DNS issues on your network.
Alternative DNS Troubleshooting Tools
There are a few alternatives if nslookup is not available on your system:
- dig – Included with Linux bind utils, offers similar DNS lookup capabilities.
- host – Simple DNS lookup tool on Linux and Windows.
- Resolve-DnsName – PowerShell cmdlet on Windows.
- drill – Advanced DNS analysis tool with a focus on security evaluations.
However, nslookup remains one of the most common and convenient DNS troubleshooting tools on Windows and Linux systems. Now you know how to fix any issues getting it running on your machine.
Conclusion
Nslookup is an essential DNS debugging tool for network admins to have in their toolkits. If you get a “nslookup command not found” error, this is likely because it is not installed or in your system’s PATH.
On Linux, install the bind-utils package and add the path to your $PATH variable. On Windows, enable the DNS Server role and add the tools path to your system PATH.
Once available, nslookup can query DNS records, check connectivity, trace delegation chains, and more. Use it to quickly troubleshoot any DNS issues you encounter!
Greetings! I am Ahmad Raza, and I bring over 10 years of experience in the fascinating realm of operating systems. As an expert in this field, I am passionate about unraveling the complexities of Windows and Linux systems. Through WindowsCage.com, I aim to share my knowledge and practical solutions to various operating system issues. From essential command-line commands to advanced server management, my goal is to empower readers to navigate the digital landscape with confidence.
Join me on this exciting journey of exploration and learning at WindowsCage.com. Together, let’s conquer the challenges of operating systems and unlock their true potential.