Linux nslookup Command: Query DNS Names and Records

nslookup queries a domain or IP address on a DNS server. It supports simple lookups and interactive queries, but for detailed DNS response analysis, dig is often clearer.

What is the nslookup command?

If you provide a name as an argument, it outputs results non-interactively, and if executed without arguments, it enters interactive mode. The default server follows the system settings, and you can specify another DNS server with the last argument. Non-authoritative answer may indicate a cached response and is not immediately an error.

Basic syntax

nslookup [option] [name|IP] [DNS server]

The installed implementation and options may vary depending on the distribution. Check the current system description with man nslookup.

Examples

Domain address lookup

Queries the address from the configured DNS server.

nslookup example.com

Specify record type

Check the MX record that represents the mail server.

nslookup -type=MX example.com

Reverse DNS lookup

Check whether the PTR record of the IP address is registered.

nslookup 192.0.2.1

Check Which DNS Server Responded

nslookup queries the default DNS server. The results may show the server used along with the response address.

nslookup example.com

Example structure of the output (addresses are illustrative):

Server:  192.0.2.53
Name:    example.com
Address: 192.0.2.10

Do not confuse the Address in the answer with the Server address used for the query. The same name can return different values depending on the DNS server, cache, and timing. If you need a detailed comparison including record type and TTL, dig is more suitable.

Main Options and Format

Options/Format Description
-type=format Select a record type such as A, AAAA, MX, or TXT.
-query=format An alias that specifies the query record type.
-timeout=seconds Adjusts the wait time for the DNS server response.
Last server argument Query a specific DNS server instead of the default.
No arguments Entering interactive mode.

Precautions when using

Do not assume that the network connection has failed just because there is no DNS response. Check the server you are using, the record format, and the cache status. nslookup does not reproduce the system's /etc/hosts handling or all name resolution paths of the application.

Frequently Asked Questions

How do you exit interactive mode in nslookup?

You can exit by typing exit at the prompt or pressing Ctrl+D.

Official Documentation

The exact behavior of the options and implementation differences can be found in the official nslookup documentation.

More in This Category
Linux host Command: Look Up DNS Names and Addresses

Linux host Command: Look Up DNS Names and Addresses

Learn how to look Up DNS Names and Addresses with the Linux host command, including practical examples, key options, and important precautions.

Linux jobs Command: List Jobs in the Current Shell

Linux jobs Command: List Jobs in the Current Shell

Learn how to list Jobs in the Current Shell with the Linux jobs command, including practical examples, key options, and important precautions.

Linux ss Command: Inspect Open Ports and Sockets

Linux ss Command: Inspect Open Ports and Sockets

Learn how to inspect Open Ports and Sockets with the Linux ss command, including practical examples, key options, and important precautions.

Linux help Command: Read Help for Bash Built-in Commands

Linux help Command: Read Help for Bash Built-in Commands

Learn how to use the Linux help command to read usage information for Bash built-in commands, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux csplit Command: Split Files at Lines or Patterns

Linux csplit Command: Split Files at Lines or Patterns

Learn how to split Files at Lines or Patterns with the Linux csplit command, including practical examples, key options, and important precautions.

Linux chgrp Command: Change a File's Group

Linux chgrp Command: Change a File's Group

Learn how to change a File's Group with the Linux chgrp command, including practical examples, key options, and important precautions.

Linux Tutorial / Install and Update Packages with APT and DNF

Linux Tutorial / Install and Update Packages with APT and DNF

Compare APT on Debian or Ubuntu with DNF on Rocky Linux for searching, installing, updating, and removing packages, including repository and transaction checks.

Linux Tutorial / Manage Files and Directories: Create, Copy, Move, and Delete

Linux Tutorial / Manage Files and Directories: Create, Copy, Move, and Delete

Practice creating, copying, renaming, moving, and deleting files and directories in a dedicated folder while checking each result safely.

Linux Tutorial / File Permissions and Safe sudo Use

Linux Tutorial / File Permissions and Safe sudo Use

Learn to read file and directory permissions, practice chmod safely, and understand when to use sudo and how to diagnose access errors.

Linux ln Command: Create Hard Links and Symbolic Links

Linux ln Command: Create Hard Links and Symbolic Links

Learn how to create hard links and symbolic links with Linux ln, choose relative or absolute targets, replace links safely, and inspect link behavior.