Wednesday, January 09, 2002

Host Command

As mentioned many times in these posts, to make a connection from your computer to another one, your machine has to find the IP number that corresponds to a given host name. This is done in the background when you use for example a browser: when you type an address in your browser the system will look for the IP number of that host (actually, for any process that requires connection to the Internet –mail, ftp, telnet, ssh, etc) the translation to IP numbers is done in the background. However, you can use the command host to do that translation yourself.

The basic way to use host is an in this example:

host a-computer-name

That will give you the IP number of a-computer-name. These IP numbers are stored in some machines called name servers. But the name servers usually keep other information associated to computers, beside the IP number, that you can find with the host command. To find some information you have to give the -t TYPE, where TYPE is the kind of information you want.

The IP number is known as the address information, and the corresponding TYPE is A. So the above command is equivalent to this:

host -t A a-computer-name

Other possible values of TYPE are the following (I’m listing only the less technical options):

  1. MX: will give you the machines that receive mail for a-computer-name
  2. CNAME: some machines have more than one name; this option will give you the "real" name of the machine, all other names being aliases to that "real" one
  3. NS: name server, will tell you which machine has all this information for the a-computer-name machine (not for your machine!)
  4. PRT: will do the reverse translation, namely convert IP numbers to host names. Actually, with the latest versions of host you do not need to give this option, that is host is equivalent to host -t PTR

If you want to see all records associated to a host try

host -a a-computer-name

where -a stands for all. The output will look quite complicated to a person not familiar with the way name servers work.

To see how the command host works, what is doing in the background, you can try the verbose option:

host -v a-computer-name

Note: before the command host appear the way of doing all the above was with the command nslookup. This command still works, but according to the (bind) documentation it might be removed in the future, so you better start using host if you have not switched to it yet.