The HOSTS file is used to translate a host name to an IP (Internet Protocol) address without querying the DNS (Domain Name System) server.
For example, suppose you would like to search the web using Google. You start your browser and enter the 'www.google.com' host name. Communication on the Internet is based on IP addresses rather than host names, so behind the scenes the operating system checks if the HOSTS file has a mapping for www.google.com to an IP address. If there's no mapping in the HOSTS file the operating system queries the DNS server that returns 126.96.36.199 - which is Google's IP address - and then the browser requests Google's search page.
The remainder of the document provides more detailed information about the HOSTS file, such as how to edit it manually, how to use it for blocking content, known problems and work-arounds, etc.
The following is an example of a HOSTS file that redirects www.google.com to 188.8.131.52, which is Yahoo's IP address. It also redirects wwww.yahoo.com to 184.108.40.206, which is Google's IP address. The line starting with # is a comment that will be ignored.
# An example HOSTS file.
The HOSTS file is often used to block potentially unwanted content, such as advertisements, cookies, hijackers, spyware, adware, pornography, etc.
If you know the host name of the machine that serves the unwanted content, you can redirect it to 127.0.0.1, which is the local IP address of your machine. For example, assume you have redirected the ad.doubleclick.net ad server to 127.0.0.1. Every time your browser tries to load an image or a flash animation from the ad.doubleclick.net ad server, it will be redirected to your machine instead. As a result, the browser will not be able to show any content from this ad server.
Unfortunately, there's no user-friendly
notification when the HOSTS
file blocks a site. In fact, Internet Explorer users will only
get a general
'The page cannot be displayed' message,
assuming you are not running a local
web server. The same message appears
when a web site is unavailable for other
reasons that HOSTS file blocking.
If an image is blocked, you'll see a box with a red cross. The same box will also appear if the image is unavailable for reasons other than HOSTS file blocking.
The HOSTS file is named 'hosts' and editable with any text editor, such as Notepad or Wordpad. Before editing, backup the current HOSTS file. The exact location of the file is determined by the 'HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Tcpip\Parameters\DataBasePath' registry key. The file generally appears at:
Sometimes machines use a HTTP (Hyper Text Transfer Protocol) proxy to handle the task of downloading and caching web content. The proxy also handles the translation from host names to IP addresses. As a result, the local HOSTS file may not be queried.
Internet Explorer to use the local HOSTS file,
please go through the following sequence:
Start Internet Explorer -> Tools ->
Internet Options -> Connections.
Double-click your connection in the list
labelled "Dial-up and Virtual Private Network settings.
Check the box for "Bypass proxy servers for local addresses".
Note that this fix only applies to users running Internet Explorer using a connection configured to use a HTTP proxy.