The nslookup
command is a built-in network administration tool available on Windows, macOS, and many Linux distributions. It is used to query DNS servers to retrieve information about domain names, IP addresses, and DNS records.
Basic Syntax:
nslookup [hostname] [DNS server]
Components:
hostname
: The domain name (e.g.,example.com
) or IP address you want to query.DNS server
(optional): The DNS server to use for the query. If omitted, the system’s default DNS server will be used.
Common Use Cases:
- Query the Default DNS Server for a Domain Name:
nslookup example.com
This resolvesexample.com
using your default DNS server and returns its IP address. - Query a Specific DNS Server:
nslookup example.com 8.8.8.8
This queries Google’s public DNS server (8.8.8.8
) to resolveexample.com
. - Query Specific DNS Record Types: You can specify the type of DNS record to retrieve by using the
set type
command:- A Record (IPv4 Address):
nslookup -type=A example.com
- MX Record (Mail Exchange):
nslookup -type=MX example.com
- NS Record (Name Servers):
nslookup -type=NS example.com
- TXT Record (Text Records):
nslookup -type=TXT example.com
- A Record (IPv4 Address):
- Perform a Reverse DNS Lookup: To find the domain name associated with an IP address:bashCopy code
nslookup 8.8.8.8
- Interactive Mode: You can run
nslookup
without arguments to enter interactive mode. In this mode, you can issue multiple queries without retyping the command:nslookup
Example session:Default Server: dns.example.com Address: 192.168.1.1 > set type=MX > example.com
To exit, typeexit
. - Query with Debug Information: You can use the
debug
option to see detailed DNS query information:nslookup -debug example.com
Example Output:
Query a Domain:
nslookup example.com
Output:
Server: dns.google
Address: 8.8.8.8
Non-authoritative answer:
Name: example.com
Address: 93.184.216.34
Query an MX Record:
nslookup -type=MX example.com
Output:
Server: dns.google
Address: 8.8.8.8
Non-authoritative answer:
example.com MX preference = 10, mail exchanger = mail.example.com
Key Commands in Interactive Mode:
set type=[record_type]
: Specify the type of DNS record (e.g., A, MX, TXT, etc.).server [DNS_server]
: Change the DNS server for queries.exit
: Exit interactive mode.
Pros and Cons of nslookup
:
Pros:
- Built-in on Windows, macOS, and most Linux distributions.
- Simple and easy to use for basic DNS queries.
- Can perform reverse lookups.
Cons:
- Output is less detailed than
dig
. - Limited options for advanced DNS troubleshooting compared to
dig
orhost
. If you would like to learn more about ‘dig’ – go here.
Comments are welcomed below from registered users. You can also leave comments at our Discord server.
If you would like to see more content and articles like this, please support us by clicking the patron link where you will receive free bonus access to courses and more, or simply buying us a cup of coffee!