Master nslookup on Linux: Install and 7 Essential Commands

This guide shows how to install the nslookup tool on Debian/Ubuntu and CentOS/RHEL systems and provides seven practical usage examples, including querying IP addresses, specifying DNS servers, retrieving specific record types, performing reverse lookups, setting search domains, using the set command, and exiting the interactive mode.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Master nslookup on Linux: Install and 7 Essential Commands

Installation on Debian/Ubuntu

Use the apt package manager to install the dnsutils package, which provides the nslookup command.

sudo apt update
sudo apt install dnsutils

Installation on CentOS/RHEL

Use yum or dnf to install the bind-utils package, which includes nslookup. Choose the command that matches your system version.

# For yum‑based systems
sudo yum install bind-utils

# For dnf‑based systems
sudo dnf install bind-utils

Usage 1: Query an IP address

Run nslookup followed by a domain name to retrieve its IPv4 address.

nslookup example.com

Usage 2: Specify a DNS server

You can direct the query to a particular DNS server instead of the default local resolver.

nslookup example.com 8.8.8.8

Usage 3: Query a specific DNS record type

Use the -type option to request records other than the default A record, such as MX (mail exchange) records.

nslookup -type=MX example.com

Usage 4: Perform a reverse lookup

Provide an IP address to retrieve the associated domain name.

nslookup 1.1.1.1

Usage 5: Set a search domain

When querying, you can define a search domain to automatically append to unqualified hostnames.

nslookup -d2 example.com

Usage 6: Use the set command

Inside the interactive nslookup prompt, the set command lets you modify options such as query type or timeout.

nslookup
set type=A
example.com

Usage 7: Exit the interactive mode

In interactive mode, type exit or quit to leave nslookup.

exit

The nslookup tool is useful for diagnosing DNS problems such as failed name resolution, stale caches, or misconfigurations, but keep in mind that results may be affected by local DNS cache settings or the configuration of the queried DNS server.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

network troubleshootingLinuxcommand-lineDNSCentOSUbuntunslookup
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

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.