The hosts File

Each entry in the /etc/hosts file contains an IP address and the names associated with that address. For example, the host table on crow might contain the following entries:

Listing 4.1: A Sample Host Table

$ cat /etc/hosts

localhost localhost.localdomain crow wren robin hawk

The first entry in this table assigns the name localhost to the address (Every computer running TCP/IP assigns the loopback address to the hostname localhost.) Network 127 is a special network address reserved for the loopback network, and host is the loopback address reserved for the local host. The loopback address is a special convention that permits the local computer to address itself in exactly the same way that it addresses remote computers. This simplifies software because the same code can be used to address any system, and because the address is assigned to a software loopback interface (lo), no traffic is sent to the physical network.

The second entry in the table is the entry for crow itself. The entry maps the address to the name and to the alias crow. Alias hostnames are primarily used to provide for shorter names, as in the example, but they are also used to provide generic names such as mailhost, news, and www. Every networked computer with a permanent address has its own hostname and address in its host table.

Every Linux system has a host table with the two entries just discussed, and some, such as the system in Listing 4.1, have a few additional entries for other key systems on the local network. This small table provides a backup for those times when DNS might not be running, such as during the boot process.

Was this article helpful?

0 0

Post a comment