How-to: Block Websites in the Hosts File

Block site through the Hosts fileIt’s not just ‘Adult’ sites that throw unwanted browser windows and tabs on your screen. I have two ISP’s which pull the same trick for advertising purposes. Ordinarily you would put these on a blacklist in a browser extension such as Ad-block, but then the crafty little so-and-so’s have an ad-block detector running in javascript which complains and even blocks you going any further into the main site.

I have no problem with sponsored sites with advertising, I do have a problem with bad-mannered programmers hijacking my browser. You could add a firewall rule to block this unwanted inbound traffic. You could also hard-write a block at the operating system level…

One counter-measure can be inserted into Windows, Mac and Linux which all employ a hosts file controlling a base level of internet access.

Navigate to \WINDOWS\system32\drivers\etc (Windows) or \etc\ (Linux) and find a plain text file named simply HOSTS. Back this up before you start editing.

Open it in a text editor (notepad or gedit or similar) and note that the first line must always state; 127.0.0.1 localhost.

Below the entry “127.0.0.1 localhost” add 127.0.0.2 the internet address of the exception, such as http://www.sitenametoblock.com to render that site inaccessible.

127.0.0.1 localhost
127.0.0.1 http://www.blockedsite.com
You can use either 127.0.0.1 or 0.0.0.0 for any number of URL’s you want to block.

You will need to restart the machine to reload the hosts file. This doesn’t work in all circumstances but takes care of the majority of irritants. AJS

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s