How To Block A Specific Website with the Host File

The internet is a great place to find a lot of great and free information. There is also a lot of not so good content or not appropriate content out there. Let say your kids or spouse keeps going out to a website that you don’t want them to be viewing. In this article we will walk through the steps on how to redirect the traffic from the bad site to what ever site you want.

 

(Note: In this example I am using a windows XP machine. There are a few more steps involved in changing this in Vista or windows 7. There also other tools out there that will allow you to block content type by using dns such as OpenDNS.)
 

In this example I am going to redirect Yahoo.com to Google.com

 

We are going to want to get the IP address of the site we are going to redirect the bad site to. So in this example I am going to redirect yahoo.com to google.com. I will need to find the IP address of google.com.

>p>Go to your Start menu and select run

Start > Run 

Type cmd and hit ok

 
cmd or command

You should now see a black DOS window.

Dos - cmd - command

Type the command ping google.com and hit enter

Ping site name 

You can swap out google.com with what ever site you want.

 

You should now see what the IP address is. It should be 4 sets of numbers separated by “.”. So in this example it is 209.85.171.99. write down this number.

IP address

Next thing we will need to do is locate a file named host. This file can be found in C:\WINDOWS\system32\drivers\etc

Path to Host File in Windows XP 

You will need to open this file with notepad.

 

Right click on it and select Open

Right click 

You will need to select notepad from the list of applications and hit ok

Select Notepad 

You should now see a file that looks like this.

default host file in windows XP
 

We are now going to add an entry. You will want to add it just below the 127.0.0.1 entry.

 

The first part will be the IP address of the website you are going to redirect to. So in this example it would be my Google’s IP address (209.85.171.99)

 

 

 

Enter IP address
 

The second part is the site name. This would be the bad site that you don’t want however visiting. In my example it is yahoo.com

Site name in host file 

Now that you have entered the redirect we will need to save the file and test it. If you have visited the bad site and have not closed your browser since then, you will need to close your browser and then open it for the changes to take effect.

 

You can see here that I entered Yahoo.com and it sent me to google.com.

 
Redirect in action 

So how does this work. Most websites have a domain name associated with the IP of the server. When you type in the domain name (example: yahoo.com) it first goes and looks at your host file to see if the entry is in there. If it is not then it goes out to your internet provider to find the IP address of the domain name. Since we put an entry in here for that site it uses the IP address that you supplied.

 

 

One other note. If you are still having problems you may have to flush your DNS. To do this open up the Dos window and type the following command ipconfig /flushdns.
 

ShareThis
 

If this information was useful, please consider donating a small amount to help cover bandwith costs.