Thursday, August 18, 2022

10 Examples of nslookup command in Linux and Windows

Hello guys, if you are wondering what is nslookup command and how to use in Linux and Windows then you are at right place. In the past, I have shared examples of crontab, find, grep, netstat, and curl command and In this article, I will share 10 different examples of nslookup command, each using its different powerful command line option to give you the tool you need to deal with networking  related queries. I often use nslookup command to convert a given IP address to hostname or a given hostname to IP address. For example, when I see an IP address in our log file and want to find which host that request is coming from, I use nslookup. 

Once you know the hostname you can easily identify who is the owner of that host and which apps run on that host, further zeroing down on your client. I have used nslookup extensively last year when we are migrating our 10 year old service to new host. That time it was nslookup which gives us who our clients are and which hosts are sending requests to our service before we can shutdown and move to new host.

You can see how powerful nslookup command is and why its an essential tool for every programmer be it Java or Golang developer. Anyway,  you will be learning 10 examples of nslookup command in Linux. And the learning objectives are:

What is nslookup Command?

What is it used for?

How is it used, and what situation could it be applied to?

Firstly, nslookup Command stands for name server lookup, which is good for getting information from the DNS - Domain name system. nslookup command is a tool for network administration that enables us to obtain the DNS, IP addresses, or any other thing that has to do with DNS.

Now, I shall be providing examples of how to use nslookup command.


10 ways to use nslookup command in Linux

Here are the 10 differnet ways you can use nslookup command in Linux. I have tried to include different useful nslookup command line option so that you can use this powerful command more effectively. I normally use nslookup to convert hostname to IP address or IP address to hostname in both Windows and Linux. 


1. You can use nslookup with a domain name to get its IP address 

$ nslookup google.com

That displays the IP address of google.com which is the domain name.

10 Examples of nslookup command in Windows and Linux


2. You can use it to get the name server record 

$ nslookup -type=ns <URL>

All you need to do is to specify the type and since is it the name server we've got to deal with, that is why you see ns as the type. Then followed by the domain name you have specified.


3. You could do a reverse DNS lookup

What we did at number 1 was that the command with a domain name to get its IP address. But this time around it is the opposite, we want to use the nslookup with an IP address to simply give us its domain. 

nslookup 138.341.221. 

If there is an IP address as you have typed then the domain name should come from it


4. To View any available DNS record

Still the same option type, you assign any to it then followed by the domain name, by you doing or using any already speaks a lot. It will look up any record of the domain name you have provided. learnex.com is demo of a domain name

$ nslookup -type=any learnex.com


5. How to check the NS record of a domain

NS record means nameserver record responsible domain name system zone. And the reason why you need an NS record is that the queries of the domain name system respond with a list of name servers. So in that regard, it is mandatory that your DNS zone has proper NS records, Without NS records your Zone will no longer work. Below is the command to check the NS record of a domain. sample.com is a pseudo domain name.

$ nslookup -type=ns sample.com


6. To View SOA record

Another thing you could use nslookup command with is to view the SOA record. SOA means the start of authority. This contains the authoritative information of the domain and the server as well. E.g serial number, address of the administrator, query expiration time, etc. Below is the command to see the domain's SOA record

$ nslookup -type=soa google.com


7. To View Text Records of a domain. 

There could be times you need the text record of a particular domain. Text records contain information about the users or information about the domain. To view this information, the command below is used: 

$ nslookup -type=txt google.com


8. To View Pointer Record. 

Pointer records are used for reverse DNS lookups, (This has been dealt with above) to confirm that the IP address truly belongs to a particular domain name. If you note the option of the type, is "ptr" this reverses the IP address. for instance, 6.2.1.9 becomes 9.1.2.6

$ nslookup - type=ptr [reverse-ip-addrs].in-addrs.arpa


9. To find MX  records.

 Firstly before you are shown how to do that, you need to know ow what MX record is MX stands for Mail exchanger. So To find or query mail exchanger records means that you are looking for records responsible for email exchange. This is to know if the mail servers are working well and if there is nothing to worry about. The command below helps with that

$ nslookup -query=mx sample.com


10. To change the timeout interval of a server response. 

You can manually set the timeout in seconds. If you increase it means you are giving the server more time to respond, You can reduce it as well and still see which server can respond faster. It all depends on how you set it. To run the command, we have the following

$ nslookup -timeout=30 demo.com

In this case, the timeout is set to 30 seconds


That is all about the nslookup command in Linux and how you can use it to carry out different tasks. such as to find MX records, change the timeout interval of a server's response, view Text Records of a Domain, get the IP address of a domain name e.t.c. Before you can work with nslookup you need to have it installed in your operating system. With the understanding you have had in this article, you can go ahead and run your own commands.

No comments:

Post a Comment

Feel free to comment, ask questions if you have any doubt.