The /etc/hosts File

/etc/hosts is a plain text file that associates IP addresses with host names and which is accessed by all commands that use the network in the absence of a name server.

An IP address is a unique numeric identifier for a host (i.e., computer or other device) on the Internet or other TCP/IP (transmission control protocol/Internet protocol) network. A name server is a server (i.e., a specialized computer or software) that converts human-readable host names into numeric IP addresses.

/etc/hosts contains three fields, which are separated blank spaces or tab characters. Each line contains an IP address, its domain name and any aliases for it.

A domain name is a name that uniquely identifies an IP address and is easier for humans to remember than the series of numbers that comprise IP addresses. Each domain name contains at least two parts, for example, with the part on the left the most specific and that on the right the most general. Adjacent parts are separated by a period.

/etc/hosts can be modified (e.g., adding or removing an IP address or changing a host name or alias) by the root account (i.e., system administrator) with a text editor such as gedit or vi. After changes have been made, it is necessary to restart the network in order for them to take effect. This can be accomplished by using the network command with its restart option as follows:

/etc/rc.d/init.d/network restart

In the early days of the Internet, manually updated host tables such as /etc/hosts were the only way of resolving (i.e., converting to IP addresses) host names. However, this became very cumbersome as the Internet grew, and thus it was replaced by the automated domain name system (DNS). Despite the use of DNS on the Internet, most computers still contain host tables for use during system booting and on LANs (local area networks) and other private networks.

Created September 25, 2005.
Copyright © 2005 The Linux Information Project. All Rights Reserved.