How to block ads and malicious websites using the host file

We all hate ads, don’t we?

Luckily nowadays there are many browser extensions like AdBlock and his brother AdBlock Plus that lets you block ads on the web using blocklists like EasyList. They do a great job and get better and precise in every new list and extensions updates, for example now both extensions can block ads in a page even before they get downloaded to help you save bandwidth and time since the page will load faster. But those are extensions of your web browser so they will need some RAM memory to work and also they could make your browser run slower, especially if you do some intense browsing and you have multiple tabs loaded.

Is there a way to block all possible ads, like AdBlock and AdBlock Plus do without extensions? The answer is: yes [of course] and you don’t need any additional software we just need the already present host file.

For the one who don’t know a host file is a file present in all OSs in which there is a list of websites who the user won’t be able to access. This is a [empty] host file:

So, for example if I don’t want the user able to access the New York Times website I just need to add it like this in the host file like this:

127.0.0.1            www.nytimes.com

and the website will be blocked. This principle can be used to block ads websites and already know malicious one [full of malware, viruses, etc.] but to be sure to block all of those sites you will need to add every single one of them to the host file and, trust me, there are a lot of them.

Luckly MSMVPS already did the job for us creating a host file with all those websites and they also update it once a month with newly discovered bad-websites and all the ads stuff. Here you can download the latest version:

http://winhelp2002.mvps.org/hosts.zip

There are 3 different ways to install it, based on your operative system:

  • Windows:
  1. Right click and select “Run as Administrator” on the mvps.bat file
    It will do the job for you renaming the old host file to host.mvps for backup and replacing it with the new one.
  2. Reboot
  • Mac OS X:
  1. Copy the HOST file and replace the one in private/etc/
    [If you need help to 
    reach this folder press Command+Shift+G and write “private/etc/”, then press Ok]
  2. Open the Terminal and paste this text to flush the DNS Cache:
    dscacheutil -flushcache; sudo killall -HUP mDNSResponder
  3. Reboot
  • Linux:
  1. In the Terminal run:
    vi /root/update_hosts.sh
  2.  Fill the file with:
    #!/bin/bash
    cd /tmp
    wget http://winhelp2002.mvps.org/hosts.txt
    rm /etc/hosts
    mv hosts.txt /etc/hosts
    cat ~/.etchosts >> /etc/hosts
  3.  Make the script is executable:
    chmod +x update_hosts.sh
  4.  Close the Terminal and re-open it and paste this:
    crontab -e
  5. Enter this:
  6. 59 23 * * * /root/update_hosts.sh
  7. Done.

There you have it, now your OS will block those noisy ads for you and you won’t need any AdBlock extensions, also this will also add an extra layer of security to your system.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s