Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Linux nslookup command

Linux nslookup command

Linux Command Reference Linux Command Reference


nslookup (Name Server Lookup) is a network management tool for querying Domain Name System (DNS) records. It helps users diagnose and resolve DNS-related issues and is one of the commonly used command-line tools for Linux system administrators and network engineers.

The main functions of nslookup include:


Basic Syntax

The basic syntax of the nslookup command is as follows:

nslookup [选项] [域名/IP] [DNS服务器]

Parameter Description

Parameters Description
Domain/IP The domain name or IP address to query
DNS server Specify the DNS server to use (optional)

Common options

Option Description
-type=TYPE Specify the record type to query, such as A, MX, NS, etc.
-debug Display debugging information
-port=PORT Specify the DNS server port (default 53)
-timeout=SEC Set the query timeout in seconds
-retry=NUM Set the number of retries

Usage examples

1. Basic domain query

Query the A record of a domain (default):

nslookup example.com

Example output:

Server:         8.8.8.8

Address:        8.8.8.8#53



Non-authoritative answer:

Name:   example.com

Address: 93.184.216.34

2. Query using a specified DNS server

Query using Google's public DNS server (8.8.8.8):

nslookup example.com 8.8.8.8

3. Query a specific record type

Query MX records (mail servers):

nslookup -type=MX google.com

Query NS records (name servers):

nslookup -type=NS google.com

Query TXT records:

nslookup -type=TXT google.com

4. Reverse DNS lookup (IP to domain)

nslookup 8.8.8.8

5. Interactive mode

Enter nslookup without arguments to enter interactive mode:

Example

nslookup

set

type

=MX

google.com

server 8.8.4.4

example.com

exit


Common DNS record types

Record type Description Example command
A IPv4 address record nslookup -type=A example.com
AAAA IPv6 address record nslookup -type=AAAA example.com
MX Mail exchange record nslookup -type=MX example.com
NS Name server record nslookup -type=NS example.com
CNAME Alias record nslookup -type=CNAME www.example.com
TXT Text record nslookup -type=TXT example.com
SOA Start of authority record nslookup -type=SOA example.com

Advanced usage

1. Debug mode

nslookup -debug example.com

2. Query DNS root servers

nslookup -type=NS .

3. Query a specific port

nslookup -port=8053 example.com dns-server.example.com

4. Set timeout and retries

nslookup -timeout=10 -retry=3 example.com


Common Problem Solutions

1. Query gets no response

Possible reasons:

Solutions:

Example

Check the network connection

ping

8.8.8.8

Try another DNS server

nslookup example.com 8.8.8.8

2. What does "Non-authoritative answer" mean?

It means the returned result comes from a DNS cache rather than an authoritative DNS server. To get an authoritative answer, query the authoritative DNS server for that domain.

3. How do I query the authoritative DNS server for a domain?

nslookup -type=NS example.com


Alternative tools

Although nslookup is still widely used, modern Linux systems recommend usingdigorhostCommand:

  1. dig - A more powerful DNS query tool

    dig example.com
  2. host - A simpler DNS query tool

    host example.com

Summary

nslookup is a simple and practical DNS query tool. Through this article, you should be able to:

  1. Understand the basic usage and common options of nslookup
  2. Query various types of DNS records
  3. Diagnose basic DNS-related issues
  4. Understand the differences between nslookup and other DNS tools

The best way to master nslookup is to practice. Try querying websites you often visit or your organization's name servers, and observe the results returned for different types of DNS records.


Linux Command Reference Linux Command Reference