Nameserver Lookup: nslookup



next up previous contents index
Next: Are You There? Up: Managing Networked Computing Previous: Computer's Name: hostname

Nameserver Lookup: nslookup

If you want to compute over a network, say to transfer files between machines or to run commands remotely, then your computer must know both the name and numerical address of the machines with which it will network. When everything is working, you need only know the name of the remote machine since then the system translates this name to a numerical address for you. The command nslookup is useful for testing the nameserver. Depending upon what is known, it queries the nameserver for a computer's name or address. The ``nameserver'' is a computer somewhere on the network which, when given a name of a host computer such as physics.orst.edu, ``serves up'' a numerical IP address such as 127.31.128.61.   

As discussed further in this chapter, the nameserver computer is often quite remote yet is essential for mail systems and networked computing. If your system does not use a nameserver, you must keep a list of machines and their IP addresses in the file /etc/hosts. If you are using a nameserver, the file /etc/resolv.conf will contain the IP address of the local nameserver computer as well as alternative servers (helpful if the regular nameserver goes down or is not reachable). If your machine is the nameserver for the network, your /etc/resolv.conf file may be empty.

It is easy for us to say that the file /etc/hosts should contain the ``hostnames'' (names and addresses) for all computers you may want to contact now or in the future, yet it is quite a chore to obtain and maintain such a file. The use of a nameserver takes care of this for you. The nameserver is actually a hierarchical system with domains or zones of responsibility. Let's say you issue the command:

% telnet physics.orst.edu   	Connect me to physics.orst.edu.  

Your local nameserver may not know about physics.orst.edu, but it does know that if it can't resolve a name (find its address), it should contact one of the national nameservers on the Internet. That national nameserver may not know about every specific machine either, but it does know that the nameserver for the domainorst.edu is ns1.orst.edu, and it knows the address of that machine. The national nameserver consequently contacts the orst.edu nameserver, gets the information for physics.orst.edu, and then passes it back down the network until your machine get the address. You then can complete your telnet. 

Here is a sample/etc/resolv.conf file:


domain orst.edu nameserver 127.31.128.61 nameserver 127.31.128.245 nameserver 127.31.31.62

This resolv.conf file defines the domain to be orst.edu, the primary nameserver to be ...61, and then two alternative nameservers as well. The system will go through alternative servers in the order given if earlier nameservers fail to perform. If the primary nameserver is not responding, you may notice something like a 1-minute delay while the system makes sure the primary server fails before contacting an alternative.

If the nameserver is not working, remote commands may fail. You will still be able to ``ping'' the remote machine using the IP address rather than the name, but that just proves that you are still connected. To add to your problems, you may also have problems opening new X Window applications and surely will have problems with NFS mounts. If you try to cd to an NFS-mounted directory, your shell (command line interpreter) will ``hang,'' that is, not allow any further input. This will also happen to commands like df when it tries to show the size of the NFS-mounted file system.

Actually, nslookup is a complex command with many options, is not available on all systems, and should be checked via your system's man pages. As an example, we show here some examples of using nslookup to test if the nameserver if working, to get an IP address for a hostname, and to get the hostname when we know the IP address:

$ nslookup   	Lookup with no options.   
* Can't find server name for address 127.31.128.61: Timed out   	   
Default Server:  ns2.orst.edu   	Second choice.   
Address:  127.31.128.245   	   
> [ctrl]-d   	We use [ctrl]-d to exit.   

Here nslookup is unable to contact the primary server and so switches, after a long pause (Timed out), to the first alternative in the /etc/resolv.conf file. If no alternative had been available, nslookup would have given a message stating this and then terminated. The prompt > means nslookup is in command mode, and we got it out of command mode with [ctrl]-d.

We next ask the nameserver for an IP address of a hostname:

$ nslookup   	Lookup with no options.   
Default Server:  ns1.orst.edu   	Primary server is found.   
Address:  127.31.128.61   	   
> physics.orst.edu   	We ask for a familiar address.   
Server:  ns1.orst.edu   	The name of the server is repeated.   
Address:  127.31.128.61   	   
Name:    physics.orst.edu   	The query succeeded.   
Address:  127.31.16.10   	   
> nr.tromso.no   	We look up an international address.   
Server:  ns1.orst.edu   	   
Address:  127.31.128.61   	   
Name:    nr.tromso.no   	Server returns the address.   
Address:  127.231.7.97   	   
Aliases: ftp.tromso.no   	   
> fake.orst.edu   	We ask for a machine that does not exist.   
*** ns1.orst.edu can't find fake:   	Server returns an error message:   
Non-existent domain.   	   
> [ctrl]-d   	We use [ctrl]-d to exit.   

If you do something like this to test your nameserver, you should try several hostnames, including some that you know, as a check. Nameservers can contain lots more information that just IP addresses; for example, they can give routes for delivering mail or give characteristics of the workstation's hardware. In the example below we make a different type of query. We ask for the alphabetic hostname of a computer whose numerical IP address we know, that is, the reverse of what we did above:

$ nslookup   	Lookup with no options.   
Default Server:  ns1.orst.edu   	Primary server found.   
Address:  127.31.128.61   	   
> set type=PTR   	We ask for a different type of query.   
> 
.16.31.127.in-addr.arpa. We reverse address and add the suffix, note ending period. 10.16.31.127.in-addr.arpa. Host name = physics.orst.edu > [ctrl]-d We use [ctrl]-d to exit.

If your nameserver fails to respond for an extended period, you may want to switch to using the /etc/hosts file. It is a good idea to keep the /etc/hosts file up to date with the remote machines you use the most. Then, after the nameserver fails, move /etc/resolv.confto /etc/resolv.conf.bak and the system will use the /etc/hosts file instead of the nameserver. Be sure to ``move'' the /etc/resolv.conf.bak file back to /etc/resolv.conf when the nameserver comes back up.gif Note that nslookup will not work with the /etc/resolv.conf file renamed unless you specify which server to contact using command options. This is how you can check whether the nameserver is working again:

$ nslookup - 127.31.128.61   	Use the ns1.orst.edu server.   
Default Server:  ns1.orst.edu   	   
Address:  127.31.128.61   	   
>    	   



next up previous contents index
Next: Are You There? Up: Managing Networked Computing Previous: Computer's Name: hostname