As you learned earlier in this hour, a hosts file is a file containing a table that associates hostnames to IP addresses. Hostname resolution was developed before the more sophisticated DNS name resolution, but hostname resolution is still used on some networks, especially smaller networks that do not require the overhead and expense of operating DNS. Some networks might use a hosts file for local lookups and still use DNS for remote queries, such as lookup for Internet access. Configuring hostname resolution on a small network is usually very simple. Operating systems that support TCP/IP recognize the hosts file and use it for name resolution with little or no intervention from the user. The details for configuring hostname resolution vary, depending on the implementation. The steps are roughly as follows:
The hosts file contains entries for hosts that a computer needs to communicate with, allowing you to enter an IP address with a corresponding hostname, an FQDN, or other aliases statically. Also, the file usually contains an entry for the loopback address, 127.0.0.1. The loopback address is used for TCP/IP diagnostics and represents "this computer." To statically enter an IP address means that after it is entered, the address must be changed manually. The following is an example of what a hosts file might look like (the IP address of the system is on the left, followed by the hostname and an optional comment about the entry):
When an application on a computer needs to resolve a name to an IP address, the system first compares its own name to the name being requested. If there is no match, the system then looks in the hosts file (if one is present) to see whether the computer name is listed. If a match is found, the IP address is returned to the local computer and, as you learned in earlier hours, is used with ARP to obtain the hardware address of the other system. Now communication between the two can take place. If you're using hosts files for name resolution, a change to the network forces you to edit or replace the hosts file on every computer. You can use a number of text editors to edit the hosts file. On a Unix system, use a text editor such as vi, Pico, or Emacs; on Windows, use Notepad; on DOS-based computers, use Edit. Some systems also provide TCP/IP configuration tools that act as a user interface to configure the hosts file. When you create or edit the hosts file, be sure to keep the following points in mind:
A hosts file is a very efficient and simple way to provide name resolution for a small, isolated TCP/IP network. Some of the implementation details differ, depending on the operating system. Consult your vendor documentation. |