JustGeek.in Tech, simplified.

About nslookup

In this post, we will explore nslookup (Name Server Lookup) and its practical usage examples.

What is nslookup?

nslookup is a command-line tool that allows you to query DNS (Domain Name System) records. With it, you can:

  • Obtain the IP address of a given hostname or domain.
  • Perform reverse DNS lookups (find the hostname associated with an IP address).

Installation

If the nslookup command is not found on your CentOS machine, you need to install the bind-utils package. Here’s how:

Error Example:

$ nslookup google.com
-bash: nslookup: command not found

Installation:

Run the following command:

$ yum install bind-utils

Once installed, you can start using the nslookup command.

nslookup Command Examples

Here are some commonly used nslookup commands:

1. Display the IP Address of a Domain

Use the nslookup command followed by a domain name to retrieve its IP address.

$ nslookup justgeek.in
Server:         8.8.8.8
Address:        8.8.8.8#53

Non-authoritative answer:
Name:   justgeek.in
Address: 151.101.2.159

2. Fetch DNS Records

Retrieve specific DNS records, such as MX (Mail Exchange) records, using the -type option.

Example: Retrieve MX Records

$ nslookup -type=mx justgeek.in
Server:         8.8.8.8
Address:        8.8.8.8#53

Non-authoritative answer:
justgeek.in     mail exchanger = 30 mx3.zoho.in.
justgeek.in     mail exchanger = 20 mx2.zoho.in.
justgeek.in     mail exchanger = 10 mx.zoho.in.

3. Find Name Servers

To list the nameservers of a domain, use the nslookup command without any additional flags.

$ nslookup -type=ns justgeek.in
Server:         8.8.8.8
Address:        8.8.8.8#53

Non-authoritative answer:
justgeek.in     nameserver = jerome.ns.cloudflare.com.
justgeek.in     nameserver = kia.ns.cloudflare.com.

4. Perform Reverse DNS Lookup

Use an IP address as input to find the associated hostname.

$ nslookup 45.77.77.200
200.77.77.45.in-addr.arpa       name = 45.77.77.200.vultrusercontent.com.

5. Query a Specific DNS Server

Specify a particular DNS server to query by appending its address to the nslookup command.

$ nslookup redhat.com ns1.redhat.com
Server:         ns1.redhat.com
Address:        209.132.186.218#53

Non-authoritative answer:
Name:   redhat.com
Address: 209.132.183.105

Conclusion

The nslookup command is a powerful tool for querying and troubleshooting DNS records. Itâs especially useful for network administrators and developers who work with DNS configurations.