How To Direct and Reverse Ip Look Up With Nslookup In Linux and Windows?


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]
  • name is the domain name we want to use
  • server is the DNS server we want to use where if not specified the system provided DNS server will be used.

Interactive Usage

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.

$ nslookup
Open nslookup interactive shell
Open nslookup interactive shell

We will get a shell to enter related commands. Query some domain name.

poftut.com
Query DNS with Nslookup
Query DNS with Nslookup

We get the IP address of the domain in interactive mode. To exit interactive mode use exit command like below.

Interactive Usage
Interactive Usage

Reverse Lookup

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 8.8.8.8
Reverse Lookup
Reverse Lookup

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 8.8.8.8
poftut.com
Set New DNS Server
Set New DNS Server

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
MX Lookup or Get Mail Server Domain Name
MX Lookup or Get Mail Server Domain Name

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
Get Soa Server Domain Name
Get Soa Server Domain Name

We will get information about mail address first name server etc. from soa request.

LEARN MORE  How To Secure Linux From Automated Attacks?

Batch Mode

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 shell.

$ nslookup poftut.com
Batch Mode
Batch Mode

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
Specify Record Type
Specify Record Type

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 poftut.com .

$ nslookup -type=ns poftut.com
Query NS Record Of A Domain 
Query NS Record Of A Domain

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 poftut.com.

$ nslookup -type=mx poftut.com
Query MX Record Of A Domain For Mail Server
Query MX Record Of A Domain For Mail Server

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
Query SOA Record Of A Domain
Query SOA Record Of A Domain

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
List All Ns Records Of A Domain
List All Ns Records Of A Domain

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 8.8.8.8 as DNS server. We can also specify the DNS server domain name.

$ nslookup -type=any poftut.com 8.8.8.8
Use Different DNS Server
Use Different DNS Server

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 60.

$ nslookup -port=60 poftut.com

Debug Transaction

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
Debug Transaction
Debug Transaction

Leave a Comment