Host File

By vaidyashish

The hosts file is a computer file used to store information on where to find a node on a computer network. This file maps hostnames to IP addresses. The hosts file is used as a supplement to (or instead of) the domain name system on networks of varying sizes. Unlike DNS, the hosts file is under the control of the local computer’s administrator.

Location and default content

The hosts file is located in different locations in different operating systems and even in different Windows versions: [1]

  • Windows NT/2000/XP/2003/Vista: %SystemRoot%\system32\drivers\etc\ is the default location, which may be changed. The actual directory is determined by the Registry key \HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\DataBasePath.
  • Windows 95/98/Me: %WinDir%\
  • Linux and other Unix-like operating systems (including iPhone OS): /etc
  • Mac OS 9 and earlier: System Folder: Preferences or System folder (format of the file may vary from Windows and Linux counterparts)
  • Mac OS X: /private/etc (uses BSD-style Hosts file)
  • OS/2 and eComStation: "bootdrive":\mptn\etc\
  • Symbian 1st/2nd edition phones: C:\system\data\hosts
  • Symbian 3rd edition phones: C:\private\10000882\hosts, only accessible with file browsers with AllFiles capability, most are not

Default content on Windows operating systems

In Windows, the default hosts file is often blank or it contains (inactive) comment lines followed by IPv4 or IPv6 localhost entries.

127.0.0.1       localhost
::1             localhost

Creating a Hosts File

Generally, the entries in the hosts file have to be created one way or the other. The IP address corresponding to an URL has to be looked up and entered. While those familiar with the PING function can do this themselves, the task would rapidly become too tedious for more than a few sites. Also, many sites regard PING as a nuisance and block it. Fortunately, others have created hosts files that can be downloaded. Several references are given in the sidebar.

Speeding Up Browsing

Many of the so-called Web accelerators that are available as freeware or as part of commercial packages make use of the hosts file. The idea is that if you can resolve IP addresses on your own computer instead of waiting for a DNS server to do it, you can cut the time required to find a Web site. If you have a slow connection or if the servers are very busy, you might shave a second or two off the connection time of your most used sites. Or on the rare occasion when DNS servers are down, you might even be able to continue to use the Web.

However, there are several drawbacks to using a hosts file. The most obvious is its size limitation. Only a small subset of all the registered Web addresses will be in a hosts file. This can be useful in speeding up your homepage and other pages that you visit regularly but many sites will still need the DNS server. Of course, many people visit only a relatively small number of sites on any regular basis and the fractional seconds saved each time may be attractive to them. Note that a hosts file that is much over 100 KB can actually slow up browsing in Windows XP unless the service “DNS Client” is set to manual start. (Managing services is discussed on another page.) In fact Windows XP SP2 is said to ignore the hosts file entirely if the DNS Client service is running.

Another problem is that the numerical IP corresponding to a particular URL can change. This can cause unexpected “The page cannot be displayed” error messages and inability to connect to sites. Thus, it is necessary to make sure that the hosts file is kept up-to-date.

My own personal experience is that no overall gain in efficiency results from using the hosts file to resolve IP addresses. The time saved in access time is more than cancelled by the time spent updating the IP addresses and the aggravation of sites that won’t connect. Those who rarely access more than a few sites might possibly benefit as long as they keep in mind the chance of not being able to connect to a site because the IP address has changed.

Blocking Adware

Perhaps the biggest use of the hosts file is to block sites that are regarded as undesirable or to block ads. This done by assigning the loopback IP 127.0.0.1 to an URL that you wish blocked. Thus an entry might be: “127.0.0.1 www.unwanted.com” (without quotes). Any request for such an IP address just gets sent right back to your own computer.

In order to see how ads can be blocked this way, we need to look briefly at the process involved in downloading a Web page to our computer. A Web page consists of many files which the browser puts together and forms into a single page for display on our computer. The various files need not come from a single source and many, especially ads and banners, can be from URLs other than the one initially addressed. To see where a graphic or ad comes from, right-click on it to bring up the context menu. Then left-click “Properties”. The Properties Sheet will show the URL that is the source of the graphic. (This doesn’t work for Adobe/Macromedia Flash ads.)

By putting a list of the URLs of the largest advertising agencies into the hosts file, many ads can be blocked. A number of people have compiled hosts files with large numbers of URLs for ads. References are given in the sidebar. When using this method, Web pages may have areas with the error message, “The page cannot be displayed”” where the ad would normally appear. Or you may just get a red “X” with a little bit of text. Ads that originate on the same site as the main page, however, will still appear. Because the blocked ad files do not have to be downloaded, pages tend to connect faster.

There can be problems, however. The compilers of ad-blocking hosts files can be a little zealous about privacy and sometimes block sites many of us would like to see. The files also often block counters and other java script applets that are pretty harmless or even useful. Further, sometimes using a hosts file can keep an entire page from downloading or interfere with navigation. The subject of ad-blocking is rather complicated, with philosophical as well as technical aspects, and cannot be discussed in detail in our limited space. There are many ad-blocking software programs that do more than use just a hosts file. For the Firefox browser, the Adblock extension works very well.

The bottom line on a hosts file, from my own personal view, is that it is probably not worth the effort for ad blocking. I have tried using one a number of times and I have always ended up removing it. I find alternate methods with special software or browser configuration techniques to be preferable.

Blocking Malware or Undesirable Sites

Hosts files are also sometimes recommended as a way to block known phishing sites or sites where downloads of malware can occur. Also known pornographic sites are sometimes blocked this way. Some may like this method but my personal opinion is that using Internet security programs together with the Internet Security Zones in Internet Explorer or Firefox extensions is better. The latest versions of Internet Explorer and Firefox also have anti-phishing defenses built in.

A good discussion of using the hosts file to block unwanted sites is here. If you are going to use a hosts file, the one provided there is a good choice. Also, check their host files FAQ.


Leave a Reply