nslookup

networkingLinux/Unix/Windows
The nslookup command is one of the most frequently used commands in Linux/Unix-like operating systems. nslookup Query Internet name servers for domain name or IP address mapping

Quick Reference

Command Name:

nslookup

Category:

networking

Platform:

Linux/Unix/Windows

Basic Usage:

nslookup [options] [arguments]

Common Use Cases

    Syntax

    nslookup [options] [hostname/IP] [server]

    Options

    Option Description
    -type= Specify the DNS record type to query (a, aaaa, mx, ns, soa, txt, etc.)
    -query= Synonym for -type=
    -debug Enable debug mode
    -timeout= Set the timeout for a query in seconds
    -port= Set the port to use for queries
    -recurse Ask for recursive service (default)
    -norecurse Don't ask for recursive service
    -ndots= Set number of dots that must be in name for it to be absolute
    -retry= Set number of retries
    -vc Use virtual circuit (TCP instead of UDP)

    Common DNS Record Types:

    Record Type Description
    A IPv4 address record
    AAAA IPv6 address record
    CNAME Canonical name record (alias)
    MX Mail exchange record
    NS Name server record
    PTR Pointer record (for reverse DNS lookups)
    SOA Start of authority record
    TXT Text record
    ANY All records (may be restricted by some DNS servers)

    Interactive Mode Commands:

    Command Description
    server NAME Set default server to NAME, using current default server
    lserver NAME Set default server to NAME, using initial server
    set OPTION Set an option (type, querytype, class, timeout, etc.)
    exit Exit the program
    help Print help information

    Examples

    How to Use These Examples

    The examples below show common ways to use the nslookup command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    # Basic Examples Basic
    nslookup example.com
    Query the default name server for the A record of example.com.
    nslookup 93.184.216.34
    Perform a reverse DNS lookup for the IP address 93.184.216.34.
    # Advanced Examples Advanced
    nslookup example.com 8.8.8.8 Query Google's DNS server (8.8.8.8) for information about example.com. nslookup -type=mx gmail.com Query for MX (mail exchange) records of gmail.com. nslookup -type=ns example.com Query for NS (name server) records of example.com. nslookup -type=any example.com Query for all available record types for example.com. nslookup -debug example.com Enable debug mode for detailed information about the query process. nslookup -query=txt example.com Query for TXT records of example.com. nslookup -query=soa example.com Query for SOA (Start of Authority) record of example.com. nslookup > server 8.8.8.8 > set type=aaaa > google.com Query for IPv6 (AAAA) records of google.com using Google's DNS server.

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    The nslookup (Name Server Lookup) command is a network administration tool for querying Domain Name System (DNS) servers to obtain domain name or IP address mapping information. It's one of the oldest and most widely available DNS query tools, present in virtually all major operating systems including Linux, Unix, macOS, and Windows. Originally developed as part of the BIND (Berkeley Internet Name Domain) package, nslookup allows system administrators, network engineers, and users to perform DNS lookups manually. While newer tools like 'dig' have become more popular among professionals for their more detailed output and expanded features, nslookup remains widely used due to its simplicity and ubiquity. Key features of the nslookup command: 1. Dual-Mode Operation: nslookup can be used in both interactive mode (by running just 'nslookup' without arguments) and non-interactive mode (by specifying queries directly on the command line). 2. Record Type Flexibility: It can query for various DNS record types including A (IPv4 addresses), AAAA (IPv6 addresses), MX (mail exchange servers), NS (name servers), SOA (start of authority), TXT (text records), and more. 3. Server Selection: Users can specify which DNS server to query, allowing for testing of different DNS servers or troubleshooting DNS propagation issues. 4. Reverse Lookups: nslookup can perform reverse DNS lookups, determining the domain name associated with an IP address. 5. Debug Option: The -debug flag provides detailed information about the query process, useful for diagnosing DNS-related issues. 6. Cross-Platform Consistency: The command works similarly across different operating systems, making it valuable for cross-platform network administration. Common use cases for nslookup include: - Verifying DNS record configurations after making changes to DNS settings - Troubleshooting email delivery issues by checking MX records - Diagnosing name resolution problems in networks - Checking DNS propagation across different DNS servers - Verifying that DNS servers are responding correctly - Discovering DNS information about domains for security assessments - Educational purposes for understanding how DNS works While nslookup is considered deprecated by its authors in favor of 'dig', it remains installed by default on most systems and continues to be widely used due to its simplicity and familiarity. For many quick DNS queries, nslookup provides all the necessary functionality without the more complex output of newer tools. It's worth noting that nslookup may occasionally provide results that differ from what applications experience, as it bypasses the system's normal name resolution mechanisms and queries DNS servers directly. For testing exactly what the system would resolve in normal operation, commands like 'getent hosts' might be more appropriate.

    Related Commands

    These commands are frequently used alongside nslookup or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the nslookup command works in different scenarios.

    $ nslookup
    View All Commands