Names
nslookup
The nslookup command asks a DNS server for the address behind a name and prints which server answered.
nslookup NAME asks the first DNS server in /etc/resolv.conf and prints that server, then the answer. It
ships with Windows, macOS and most Linux systems, so it is the check to reach for on a machine you don't know. It asks
DNS and nothing else: it never reads /etc/hosts, so when nslookup and a program disagree, that file is why.
dig prints far more of the answer.
nslookup command usage
nslookup NAME [SERVER] nslookup -type=TYPE NAME [SERVER]
Options
-
-type=a - ask for the record type after =: a, aaaa, mx, ns, txt or cname
-
10.0.1.2 - as a second word, the server to ask instead of the one in /etc/resolv.conf
nslookup examples
-
nslookup webServer.lab - Asks the configured DNS server for webServer.lab's address.
-
nslookup webServer.lab 10.0.1.2 - Asks the server at 10.0.1.2 directly, skipping /etc/resolv.conf.
-
nslookup -type=a webServer.lab - Asks for the IPv4 address alone.
-
nslookup -type=mx example.lab - Asks which mail servers take the domain's mail.
Reading the output
$ nslookup zoe.lab Server: 10.0.1.2 Address: 10.0.1.2#53 Name: zoe.lab Address: 10.0.2.10
ServerandAddress: the DNS server that answered.#53is its port.Nameand theAddressunder it: the answer, the address that goes with the name.
Pitfalls
- It skips
/etc/hosts, so a program can reach a different machine from the onenslookupnames.