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; localhost.

Below the entry “ localhost” add the internet address of the exception, such as to render that site inaccessible. localhost
You can use either or 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: Logo

You are commenting using your 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