Hosted Environments
Managed Application Hosting, Web Hosting, and Mail Hosting Services. Superior performance, reliability and personalized service.

Call Us : 866-764-8324 (TECH)

Email : support@hostedenvironments.net

Windows Hosts File

Sat, 18th October, 2008 - Posted by Administration

The windows hosts file can be used to convert domain names , such as “www.microsoft.com”, to a numeric form that computers understand and that this is done on the Internet by special computers called name or DNS servers. The translation between human-friendly names and numeric IP names is made using large lookup tables where the correspondence between the two formats is kept. Many people are unaware that their own computer also has the capability of using a local database called a “hosts” file that is stored in the Windows folder for 9X/Me systems and in Windows/system32/drivers/etc for Windows 2000/XP . This local file, of course, is of necessity much smaller than what DNS servers use and goes back to a time when it was intended primarily for use on local networks. Nonetheless, there are applications of this file on the Internet at large that you will often see recommended. Facilitating migration from one provider to another, Speeding up browsing and blockage of ads and malware are applications of hosts files that I will discuss.

Format of Hosts File
The “hosts” file is a plain text file named just that, hosts. It may have to be created. Note that there is no extension on the file name. If you look in the folder Windowssystem32driversetc, you may find a default hosts file or a text file called “hosts.sam”. This file with the extension “sam” is a sample file and has no function other than to illustrate the format. The default hosts (or the hosts.sam) file has these contents:

——————————————————————————————————–
# Copyright (c) 1993-1999 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
127.0.0.1 localhost

——————————————————————————————————-
Make particular note of the so-called “loopback” entry:
127.0.0.1 localhost
This entry is a not an actual Internet IP address but defines a local address and can be used to direct the computer to send a packet to itself. This function is used in ad blocking and is discussed below.

No wildcards are allowed and only the main domain name is a valid entry. Directories and files at a site are not supported. Thus “www.microsoft.com” is a valid entry but “www.microsoft.com/windows98/” is not.

Since the hosts file is a text file, reading, editing, or creating it should be done in Notepad or other text editor. However, it has no extension so double-clicking will not open it automatically but will bring up the “Open with” menu instead. You can then select Notepad to open it. If your system has no hosts file and you use Notepad to create one, be sure to save the file with no extension. Notepad will automatically tack on a .txt extension otherwise. When saving, save as “hosts”, including the quotation marks.

If a hosts file exists, it is automatically searched during any process using the Windows TCP/IP stack. The search is done first before any attempt to find a DNS server is made. Thus any mistakes in hosts will result in an error message. (By the way, in its normal configuration AOL uses its own version of TCP/IP so the hosts file may not be consulted by the AOL browser.)

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.

Facilitating Migration
When you transfer your web from one provider to another you test your site on the new host before changing your DNS with the registrar. This allows you to make sure everything is in order before the outside world sees your web on the new provider. This is accomplished by adding a record to your host file that tells your machine to go to the new provider’s IP address instead of the current providers IP address. This has additional advantages if you are developing a new site, particularly with word-press, front-page, or other web design tools, and don’t want references in your pages that are linked to the IP address which may change at a later date.

For example…
Add the following line to your host file where xxx.xxx.xxx.xxx is the IP address of your new website and yourdomain.com is your domain without the WWW.
xxx.xxx.xxx.xxx yourdomain.com
The Result…
when you browse to yourdomain.com without the www you will be directed to your site on new providers server. When You browse www.yourdomain.com with the WWW you be directed to your site on existing providers server that the entire world sees.

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 but it can slow down your browsing experience.

Host File Hijacking by Malware
Some malware tries to use the hosts file by altering it so that some well-known addresses are directed to the wrong place. Thus, instead of going to microsoft.com, you might end up on a cleverly faked phishing site. A number of programs will warn you if something tries to alter your hosts file. I like WinPatrol. It has many other functions as well.

Hosts File Block List
For a good poor mans way to protect your machine from malware, spyware, and adware that includes a maintained Hosts file Blackhole List see Safer Networking Spybot Search and destroy.

More Information

For more detailed information about how Hosted Environments can help your business,
please call Hosted Environments; 866-764-8324,
Send us an email, or Submit an Information Request.

Category : Web Support
Share/Save/Bookmark

You must be logged in to post a comment.