0
0
Linux-cliHow-ToBeginner · 3 min read

How to Use nslookup Command in Linux: Syntax and Examples

The nslookup command in Linux is used to query DNS servers to find domain name or IP address information. You run nslookup [domain] to get the IP address of a domain or nslookup [IP] to find the domain name. It helps troubleshoot DNS and network issues easily.
📐

Syntax

The basic syntax of the nslookup command is:

  • nslookup [options] [domain-name | IP-address]

Here:

  • domain-name: The website or host name you want to look up.
  • IP-address: The IP address to find the domain name for (reverse lookup).
  • options: Optional flags to customize the query (like specifying DNS server).
bash
nslookup [options] [domain-name | IP-address]
💻

Example

This example shows how to find the IP address of example.com using nslookup. It also shows how to do a reverse lookup for an IP address.

bash
nslookup example.com

nslookup 93.184.216.34
Output
Server: 192.168.1.1 Address: 192.168.1.1#53 Non-authoritative answer: Name: example.com Address: 93.184.216.34 Server: 192.168.1.1 Address: 192.168.1.1#53 34.216.184.93.in-addr.arpa name = example.com.
⚠️

Common Pitfalls

Common mistakes when using nslookup include:

  • Not specifying a domain or IP, which just opens interactive mode.
  • Confusing forward lookup (domain to IP) with reverse lookup (IP to domain).
  • Using outdated or unreachable DNS servers, causing no response.

Always check your DNS server settings if queries fail.

bash
nslookup
# This opens interactive mode, not a direct query

# Correct usage:
nslookup example.com
📊

Quick Reference

CommandDescription
nslookup example.comGet IP address of example.com
nslookup 8.8.8.8Find domain name for IP 8.8.8.8 (reverse lookup)
nslookup example.com 8.8.8.8Query example.com using DNS server 8.8.8.8
nslookup -type=MX example.comFind mail servers for example.com
nslookup -debug example.comShow detailed query info

Key Takeaways

Use nslookup [domain] to find the IP address of a domain.
Use nslookup [IP] for reverse DNS lookup to find the domain name.
Specify a DNS server after the domain or IP to query a specific server.
Avoid running nslookup without arguments unless you want interactive mode.
Check your DNS server settings if queries do not return results.