In its function of resolving host names, the hosts file may be used to define any hostname or domain name for use in the local system. On some old systems a file named networks is present that is similar to a hosts file, containing names of networks. Standardization efforts, such as the format specification of the file HOSTS.TXT in RFC 952, and distribution protocols, e.g., the hostname server described in RFC 953, helped with these problems, but the centralized and monolithic nature of hosts files eventually necessitated the creation of the distributed Domain Name System (DNS). As local area TCP/IP computer networks gained popularity, however, the maintenance of hosts files became a larger burden on system administrators as networks and network nodes were being added to the system with increasing frequency. Network nodes typically had one address and could have many names. The small size of the ARPANET kept the administrative overhead small to maintain an accurate hosts file. There was no method for ensuring that all references to a given node in a network were using the same name, nor was there a way to read the hosts file of another computer to automatically obtain a copy. Each network node maintained its own map of the network nodes as needed and assigned them names that were memorable to the users of the system. The ARPANET, the predecessor of the Internet, had no distributed host name database. etc/hosts (a symbolic link to /private/etc/hosts) Registry key under HKEY_LOCAL_MACHINE\Comm\Tcpip\Hosts
It is usually named hosts, without an extension. The location of the hosts file in the file system hierarchy varies by operating system. The example illustrates that an IP address may have multiple host names ( localhost and loopback), and that a host name may be mapped to both IPv4 and IPv6 IP addresses, as shown on the first and second lines respectively. This example only contains entries for the loopback addresses of the system and their host names, a typical default content of the hosts file. For example, a typical hosts file may contain the following: Entirely blank lines in the file are ignored. Comment lines may be included they are indicated by an octothorpe (#) in the first position of such lines. Each field is separated by white space – tabs are often preferred for historical reasons, but spaces are also used. The host names map to the IPs, not vice versa. The hosts file contains lines of text consisting of an IP address in the first text field followed by one or more host names. ( April 2017) ( Learn how and when to remove this template message) Unsourced material may be challenged and removed. Please help improve this article by adding citations to reliable sources. The server notices your headers specify or and serves the correct website.This section needs additional citations for verification. In cases like this, it’s not helpful to simply access the web server at its local IP address – you need to access it at its website addresses.įor example, if you have a web server with the local IP address 192.168.0.5 that hosts websites for and, you can add the following lines to your local computer’s hosts file:Īfter saving the file, try to access both and in your web browser – if everything is working properly, you should see the different websites. Some web servers run multiple websites at the same IP address – the website you get depends on the host name you’re accessing.
If you’re running a web server on your local network, you may want to make sure it’s working properly before exposing it live on the Internet.