Home

Network Administration: The Hosts File

By: 
No items found.
|
Updated:  
2016-03-26 19:46:39
|
From The Book:  
No items found.
DNS For Dummies
Explore Book
Buy On Amazon

The entire Internet was small enough that network administrators could keep track of it all in a simple text file called the Hosts file. It simply listed the name and IP address of every host on the network. Each computer had its own copy of the Hosts file.

The trick was keeping all those Hosts files up to date. Whenever a new host was added to the Internet, each network administrator would manually update his copy of the Hosts file to add the new host’s name and IP address.

As the Internet grew, so did the Hosts file. In the mid-1980s, it became obvious that a better solution was needed. Domain Naming Service (DNS) was invented to solve this problem.

Understanding the Hosts file is important for two reasons:

  • The Hosts file is not dead. For small networks, a Hosts file may still be the easiest way to provide name resolution for the network’s computers. In addition, a Hosts file can coexist with DNS. The Hosts file is always checked before DNS is used, so you can even use a Hosts file to override DNS if you want.

  • The Hosts file is the precursor to DNS. DNS was devised to circumvent the limitations of the Hosts file. You’ll be in a better position to appreciate the benefits of DNS when you understand how the Hosts file works.

The Hosts file is a simple text file that contains lines that match IP addresses with host names. You can edit the Hosts file with any text editor, including Notepad or by using the MS-DOS EDIT command. The exact location of the Hosts file depends on the client operating system.

Location of the Hosts File
Operating System Location of Hosts File
Windows 9x/Me c:windowshosts
Windows NT/2000 c:winntsystem32driversetchosts
Windows XP and Vista c:windowssystem32driversetchosts
Unix/Linux /etc/hosts

All TCP/IP implementations are installed with a starter Hosts file. For example, the listing below shows a sample Windows 7 TCP/IP Hosts file. As you can see, the starter file begins with some comments that explain the purpose of the file.

The Windows 7 Hosts file ends with comments which show the host mapping commands used to map for the host name localhost, mapped to the IP address 127.0.0.1. The IP address 127.0.0.1 is the standard loopback address. As a result, this entry allows a computer to refer to itself by using the name localhost.

Note that after the 127.0.0.1 localhost entry, another localhost entry defines the standard IPv6 loopback address (::2). This is required because unlike previous versions of Windows, Vista provides built-in support for IPv6.

Prior to Windows 7, these lines were not commented out in the Hosts file. But beginning with Windows 7, the name resolution for localhost is handled by DNS itself, so its definition isn’t required in the Hosts file.

A Sample Hosts File

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host
# localhost name resolution is handled within DNS itself.
#127.0.0.1       localhost
#::1             localhost

To add an entry to the Hosts file, simply edit the file in any text editor. Then, add a line at the bottom of the file, after the localhost entry. Each line that you add should list the IP address and the host name that you want to use for the address. For example, to associate the host name server1.LoweWriter.com with the IP address 192.168.168.201, you add this line to the Hosts file:

192.168.168.201 server1.LoweWriter.com

Then, whenever an application requests the IP address of the host name server1, the IP address 192.168.168.201 is returned.

You can also add an alias to a host mapping. This enables users to access a host by using the alias as an alternative name. For example, consider the following line:

192.168.168.201 server1.LoweWriter.com s1

Here, the device at address 192.168.168.201 can be accessed as server1.LoweWriter.com or just s1.

A Hosts File with Several Hosts Defined:

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host
# localhost name resolution is handled within DNS itself.
# 127.0.0.1       localhost
# ::1             localhost
192.168.168.200 doug.LoweWriter.com             #Doug’s computer
192.168.168.201 server1.LoweWriter.com s1       #Main server
192.168.168.202 debbie.LoweWriter.com           #Debbie’s computer
192.168.168.203 printer1.LoweWriter.com p1      #HP Laser Printer

Even if your network uses DNS, every client still has a Hosts file that defines at least localhost.

About This Article

This article is from the book: 

No items found.

About the book author:

No items found.