How to use hosts file to block any website ?

H

block a websiteIf you are wondering how to block a website from opening then one of the possible ways to block it is using hosts file. Hosts is a file that contains lists of host names and its mapping IP addresses , Operating System first looks into the hosts file that is located in your PC and then queries the DNS for relative IP address of the host name.

 

The Possible location of hosts file for your windows is

Windows 95/98/Me c:windowshosts
Windows NT/2000/XP Pro c:winntsystem32driversetchosts
Windows XP Home / windows 7 c:windowssystem32driversetchosts

Now let us look how to block a website.

For the websites that don’t have related information in hosts file will be queried DNS to get its IP address, Suppose for the host google.com the IP address is 74.125.236.50,

You can  find the ip address of the website you want to by opening command prompt and pinging it using the command

ping www.google.com

Then it replies like

Pinging google.com [74.125.236.50] with 32 bytes of data:

The IP in the brackets is the IP address of the host , Then your PC will send http requests to that particular IP , Now if  you want to block this website all you have to do is open hosts file located in the above mentioned paths and pointing the IP of host to your local system itself. If you don’t know the IP of local system is 127.0.0.1 , Then when you try request google.com , the ip of the host is returned as 127.0.0.1 which is not true so it could not connect.

There are some websites which you want to block , may be if you are using pirated software and don’t want to let the software application to connect to its update servers or may be you don’t want to see ads of google etc. All you need to do is just mention the ip address of host name to local address as

127.0.0.1                                   google.com

127.0.0.1                                  update.microsoft.com

127.0.0.1                                  update.adobe.com

etc.., then the hosts IP address is resolved to local IP and cannot be opened. Some times this changes won’t work immediatly because of dns cache, you can flush it using command

ipconfig /flushdns

This is just blocking at your local computer level and can be accessed from different system using same internet connection.

About the author

pavankumar.p1990
By pavankumar.p1990