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 apropos Command: Search Commands by Description

Linux apropos Command: Search Commands by Description

Learn how to use the Linux apropos command to find relevant manual pages by searching description keywords, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux Tutorial / Understand systemd Services, Boot, and Logs

Linux Tutorial / Understand systemd Services, Boot, and Logs

Understand Linux boot stages and systemd units, distinguish active services from boot enablement, and inspect current-boot logs with systemctl and journalctl.

Linux dig Command: Query DNS Records in Detail

Linux dig Command: Query DNS Records in Detail

Learn how to query DNS Records in Detail with the Linux dig command, including practical examples, key options, and important precautions.

Linux tee Command: Display and Save Pipeline Output

Linux tee Command: Display and Save Pipeline Output

Learn how to display and Save Pipeline Output with the Linux tee command, including practical examples, key options, and important precautions.

Linux dd Command: Copy and Convert Data by Blocks

Linux dd Command: Copy and Convert Data by Blocks

Learn how to copy and convert files or block devices with Linux dd, choose block sizes and ranges, display progress, verify results, and avoid overwriting the wrong device.

Linux Tutorial / File Types and Metadata: ls, file, stat, and readlink

Linux Tutorial / File Types and Metadata: ls, file, stat, and readlink

Learn what ls, file, stat, and readlink each reveal about a Linux file, including type, size, timestamps, and symbolic-link targets.

Linux wget Command: Download Files from URLs

Linux wget Command: Download Files from URLs

Learn how to download Files from URLs with the Linux wget command, including practical examples, key options, and important precautions.

Linux killall Command: Signal Processes by Name

Linux killall Command: Signal Processes by Name

Learn how to signal Processes by Name with the Linux killall command, including practical examples, key options, and important precautions.

How to Check the Linux Distribution, Version, Kernel, and Architecture

How to Check the Linux Distribution, Version, Kernel, and Architecture

Learn how to identify a Linux distribution and version with /etc/os-release, then check the running kernel and CPU architecture with hostnamectl and uname. The guide also covers scripts, legacy systems, containers, WSL, and chroot environments.

Linux uname Command: Check Kernel and System Architecture

Linux uname Command: Check Kernel and System Architecture

Learn how to check Kernel and System Architecture with the Linux uname command, including practical examples, key options, and important precautions.