Most Useful Uses of nslookup

I’m still amazed how even after a few years of blogging on Unix Tutorial there’s always a command or two left that are must-haves and must-knows for majority of Unix/Linux users. nslookup is one of such commands – it helps with resolving domain names to IP addresses and back.Get IP address for a domain name

Get IP address for a hostname

This is the most basic usage of nslookup: you specify a hostname (or a domain name for website) and it gives you the IP address. This is useful for troubleshooting purposes.

greys@maverick:~ $ nslookup unixtutorial.org
 Server:        192.168.1.1
 Address:    192.168.1.1#53

Non-authoritative answer:
 Name:    unixtutorial.org
 Address: 35.222.158.224

Get hostname by an IP address

This is also useful, but can get confusing when you’re working with specifically websites and not just Linux hosts.

While it’s reasonable to expect that if website name unixtutorial.org points to 35.222.158.224 IP address, then that IP address must point back to unixtutorial.org – this is most often not the case.

greys@maverick:~ $ nslookup 35.222.158.224
 Server:        192.168.1.1
 Address:    192.168.1.1#53

Non-authoritative answer:
 224.158.222.35.in-addr.arpa    name = 224.158.222.35.bc.googleusercontent.com.

Get Name Servers for a domain

This is one of the most common troubleshooting techniques still applicable today: if a hostname resolves to a wrong IP address, you need to check if you’re using the right Name Servers (NS) for it.

greys@maverick:~ $ nslookup -query=ns unixtutorial.org
Server: 192.168.1.1
Address: 192.168.1.1#53

Non-authoritative answer:
unixtutorial.org nameserver = beth.ns.cloudflare.com.
unixtutorial.org nameserver = alec.ns.cloudflare.com.

As you can see from above, nslookup reports that unixtutorial.org domain and its names are resolved by the Cloudflare name servers called alec and beth.