Operations 5 min read

Master nslookup on Linux: Install, Query, and Advanced Usage Guide

Learn how to install nslookup on Debian/Ubuntu and CentOS/RHEL, then explore seven practical commands for querying IP addresses, specifying DNS servers, retrieving specific record types, performing reverse lookups, setting search domains, using the set command, and exiting the tool.

Raymond Ops
Raymond Ops
Raymond Ops
Master nslookup on Linux: Install, Query, and Advanced Usage Guide

nslookup is a network diagnostic tool used to query DNS records, converting domain names to IP addresses or retrieving other record types such as MX or CNAME.

Debian/Ubuntu and derivatives installation

Install via apt:

<code>sudo apt update
sudo apt install dnsutils</code>

The dnsutils package includes the nslookup command.

CentOS/RHEL and derivatives installation

Install via yum or dnf depending on the system version:

<code># For yum‑based systems
sudo yum install bind-utils

# Or for dnf‑based systems
sudo dnf install bind-utils</code>

The bind-utils package contains the nslookup command.

Usage 1: Query IP address

Run nslookup with the domain name to obtain its IP address.

<code>nslookup example.com</code>

Usage 2: Specify DNS server

Specify a DNS server for the query instead of the default.

<code>nslookup example.com 8.8.8.8</code>

Usage 3: Query specific DNS record type

Use nslookup to query record types other than A, such as MX.

<code>nslookup -type=MX example.com</code>

Usage 4: Reverse lookup

Perform a reverse lookup to find the domain name associated with an IP address.

<code>nslookup 1.1.1.1</code>

Usage 5: Set search domain

When using nslookup, you can set a search domain to specify the domain to be searched.

<code>nslookup -d2 example.com</code>

Usage 6: Use set command

nslookup provides an interactive mode where the

set

command can change query options such as timeout or query type.

<code>nslookup
set type=A
example.com</code>

Usage 7: Exit nslookup

In interactive mode, exit with the

exit

or

quit

command.

<code>exit</code>

Using nslookup helps diagnose DNS problems such as resolution failures, cache issues, or configuration errors, but results may be affected by local DNS cache or server settings.

Network TroubleshootingLinuxcommand-lineDNSnslookup
Raymond Ops
Written by

Raymond Ops

Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.