The Hosts File

Written by Mark Sanborn: Oct 18, 2007

The hosts file is a text file that specifies names of IP addresses. You may recognize this name by the term, URL. Your computer’s operating system by default will always look up the name (url) of a site through your computer first. If your computer doesn’t know the name it then forwards the request to your router or ISP’s router. If that router doesn’t know the address it goes to the next router down the line and so on until one of the routers says, I know where this is at… and points you on your way.

Uses

So what is this file normally used for you ask? Well the host file can be used in various ways. Some people use the host file to name a computer on their network so they don’t have to type in the IP address every time they want to connect. The host file can be the first defense for blocking websites that you don’t want your kids to have access to. Although it is infeasible to block all bad sites on the internet, you can block myspace.com for example if you know your workers aren’t getting anything done because they are too busy checking up on john and sally. I know there are much better ways to block a site but this is a simple way that works for most situations.

Where can I find it?

In windows the host file is located here:

c:/Windows/System32/drivers/etc/hosts

and it looks like this by default:

# Copyright (c) 1993-2006 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
::1             localhost

As you can see near the bottom the name localhost is synonymes with 127.0.0.1 so instead remembering the number 127.0.0.1 you can simply type localhost. By the way 127.0.0.1 is the loopback IP address of your own computer. So to block myspace we would simple add a new line to the text file with the following:

127.0.0.1 www.myspace.com

Anytime you requested the page myspace it would try to contact your own computer instead of myspace. Since your own computer is not myspace it will show a page not found or blank page.

To add your routers IP address to the hosts file you might add a line similar to this:

192.168.1.1 WhateverNameYouWant

Anytime you typed WhateverNameYouWant it would redirect to 192.168.1.1.

Now for the real reason I am telling you about the hosts file

Now that I have showed you a little about how the host file works. I want to warn you that some malicious programs mostly (spyware/viruses/phishing programs) will alter your hosts file in very dangerous ways. It may be as “harmless” as redirecting you from www.google.com to a slightly different looking search engine so you will think you are searching with google but you are actually using their search engine that they get paid for each time you click on an ad instead of Google. A far more dangerous alteration of the host file could be a redirect of your online bank, ebay or popular online email site. You would think you are logging into your online bank when in actuality you would be logging into a fake replica bank site that would collect your credentials to be later used against you.

Whenever you suspect you have spyware, viruses, or other malware on your computer check your hosts file and make sure there isn’t anything you haven’t put in there.

Need to print shipping labels on your site?

Checkout my product RocketShipIt for simple easy-to-use developer tools for UPS™ FedEx™ USPS™ and more.

Share: