The nslookup (name server lookup) command line tool allows you to query the DNS server from the CLI. Nslookup is used to diagnose and check DNS servers and records, and to detect problems with name resolution. In this article, we are going to look at some basic examples of how to use the nslookup command in Windows.
Table of Contents
How to Use the Nslookup Command in Windows
By default, the nslookup command sends DNS queries to the preferred name server specified in your network adapter settings. To find out the IP address of the preferred DNS server in Windows, use the command:
ipconfig /all
The nslookup command can be used in either interactive or non-interactive mode.
The following is an example of a non-interactive nslookup command:
Nslookup theitbros.com
In this example, we requested the IP address of theitbros.com domain. The nslookup queries the DNS server (it is specified in the Server line) and it returns that this name matches the IP Address 34.149.36.179.
The non-authoritative answer means that the DNS server that made the request is not the owner of the theitbros.com zone and that a recursive query to another DNS server has been used to perform the name resolution (by default, recursive DNS queries are enabled).
You can make a query against an authoritative name server by specifying its address directly in the parameters of the nslookup command:
Nslookup theitbros.com ns1.siteground.net
- If no records were found for the specified DNS name, the nslookup will return the error: *** can’t find theitbros.com: Non-existent domain
- If your DNS server is unavailable or not responding, you will receive a DNS request timed out error.
If you run the nslookup command without any parameters, the utility will switch to the interactive mode. Simply enter the DNS hostname to resolve a name to an IP address interactively:
You can perform reverse lookups (get DNS name by IP address). Just type the IP address in the nslookup interactive prompt and press Enter.
In the interactive mode of nslookup, a large number of additional options are available. Type a question (?) in the interactive console for a complete list of nslookup subcommands.
Tip. Note that nslookup commands are case-sensitive.
To close the interactive nslookup session, type exit and press Enter.
Using Nslookup to View Different DNS Records
By default, the nslookup command only returns DNS resource records of type A and AAAA, but you can use different types of resource records:
You can set specific record types to lookup using the command:
-type=<record_type>
The following types of DNS resource records can be used in nslookup:
- A
- ANY
- CNAME
- GID
- HINFO:
- MB
- MG
- MINF
- MR
- MX
- NS
- PTR
- SOA
- TXT
- UID
- UINFO
- WKS
For example, to find the authoritative name servers for a specific domain, set the record type to NS (Name Server):
set query=ns theitbros.com
List of all the mail servers that are configured for a specific domain (MX, Mail eXchange records):
nslookup -type=mx theitbros.com
In this example, this domain has 3 MX records with priorities 10, 20 and 30 (the lower the number, the higher the MX priority).
To list all the DNS records in the domain zone, run the command:
nslookup -type=any theitbros.com
List the TXT records of a domain (for example, when viewing SPF settings):
nslookup -type=TXT theitbros.com
The debug option allows you to get additional information contained in the headers of client DNS requests and server responses (lifetime, flags, record types, etc.):
set debug
You can list the currently enabled nslookup options:
> set all
Set options:
nodebug defname search recurse nod2 novc noignoretc port=53 type=A+AAAA class=IN timeout=2 retry=1 root=A.ROOT-SERVERS.NET. domain=xxx MSxfr IXFRversion=1 srchlist=xxx
Most Commonly Used Nslookup Commands with Examples
Get an IP address of the host/domain (A record):
nslookup theitbros.com
Get a host/domain’s IPv6 address:
nslookup -type=AAAA theitbros.com
List domain MX records:
nslookup -query=mx theitbros.com
List authoritative name servers for the domain (NS records):
nslookup -type=ns theitbros.com
Get the SOA record for the domain (Start of Authority — start DNS zone record, which contains information about the domain zone, its administrator’s address, serial number, etc.):
nslookup -type=soa theitbros.com
List all the available DNS records for the specified domain:
nslookup -type=any theitbros.com
Reverse DNS lookup (get the DNS record by an IP address):
nslookup 35.209.36.0
Query a specific DNS server instead of the default one (preferred DNS):
nslookup theitbros.com ns1.siteground.net
Check for a PTR record:
nslookup -type=ptr 0.36.209.35.in-addr.arpa
Change the default timeout interval for a reply:
nslookup -timeout=20 theitbros.com
Common Nslookup Errors
In this section, we list common errors that the nslookup tool may return:
- DNS request timed out — the name server doesn’t respond to the request after a certain time (timeout) and a certain number of attempts. You can set the request timeout using the set timeout subcommand. You can set the number of retry requests using the set retry.
- Non-existent domain — domain/host name does not exist;
- No response from the server — DNS server doesn’t respond to nslookup query;
- No records — there are no records on the DNS server for your query;
- Connection refused/ Network is unreachable — connection to DNS server not established;
- Server failure — the DNS server has encountered an internal error in its database and cannot provide an answer;
- Refused — the DNS server dropped the connection.
The nslookup is a powerful command for Windows administrators that allows you to find the IP address of any server by its DNS name, perform reverse DNS lookup, and get information about the various DNS records for a given domain name.