nslookup is a network tool using to query DNS to obtain a domain name or IP address? The full name of nslookup is “name server lookup”. Nslookup supports interactive and batch mode. Nslookup alternative is dig which uses underlying Operating System libraries.
nslookup Command Syntax
The syntax of nslookup command is like below.
nslookup [-option] [name | -] [server]
nameis the domain name we want to use
serveris the DNS server we want to use where if not specified the system provided DNS server will be used.
Nslookup can be used in two different modes. One is an interactive mode. In order to use nslookup interactively just enter nslookup in the command line.
We will get a shell to enter related commands. Query some domain name.
We get the IP address of the domain in interactive mode. To exit interactive mode use
exit command like below.
To get the domain name of an IP address is similar to the normal domain name lookup we will just provide the IP address of the target host like below.
$ nslookup 220.127.116.11
Set New DNS Server
By default, the system-provided DNS server is used. This is generally the first local cache and then modem configuration where this is set by ISP. DNS servers can be changed like below in interactive mode.
server 18.104.22.168 poftut.com
MX Lookup or Get Mail Server Domain Name
DNS provides information about domain names. Also, mail, sip, and other related information about the domain can be got by specifying the type parameter. In this example, we will try to get the mail server domain name.
set type=mx poftut.com
Get SOA Server Domain Name
SOA or DNS server information can get with SOA type queries. We will set the type as soa like below and then provide the
poftut.com domain name to find its SOA.
set type=soa poftut.com
We will get information about mail address first name server etc. from soa request.
Batch mode is the second mode. This mode usage is a simple command-line usage. Just provide command and related arguments. We do not need to enter specific
$ nslookup poftut.com
Specify Record Type
As DNS system have a lot of different type of records we may need to specify a specific record type in batch mode. We will use
-type option and related record types in order to list only specific record types. In this example, we will list
mx record type.
$ nslookup -type=mx poftut.com
Query NS Record Of A Domain
The main use case for the
nslookup is querying NS records. NS records provide information about DNS servers of the given domain name. In this example, we will list DNS servers of the
$ nslookup -type=ns poftut.com
Query MX Record Of A Domain For Mail Server
MX record is used to list mail servers. We can only list MX records of the given domain with the
mx type. In this example, we will list mail servers of the
$ nslookup -type=mx poftut.com
Query SOA Record Of A Domain
SOA or Start Of Authority records provides technical information about the given domain. We can query the domain with the
soa type like below.
$ nslookup -type=soa poftut.com
List All Ns (Nameserver) Records Of A Domain
Up to now, we have listed DNS related information about domain name one by one. If we need to list all related information provided by a DNS server we can use
any record type.
$ nslookup -type=any poftut.com
Use Different DNS Server For Query
The default behavior of the
nslookup command is using the default system provided DNS server. In some cases, we may need to change this default DNS server and specify one explicitly. We can add a DNS server to the end of the command. In this example, we will use
22.214.171.124 as DNS server. We can also specify the DNS server domain name.
$ nslookup -type=any poftut.com 126.96.36.199
Specify Different Than Default Port
The default port for DNS services is
53 . If we know that DNS service we will use is using different port we can explicitly specify the port number with the
-port option like below. In this example, we will specify the port number
$ nslookup -port=60 poftut.com
While getting related record types there is a lot of transaction and steps which is taken under the hood. If we need to list verbose information and want to know details about
nslookup we can use
-debug option for this.
$ nslookup -debug poftut.com