Block ads directly from the hosts file

Browser extensions for Ads blocking usually works well, but in some cases they use a lot of memory and CPU, especially with really complex web pages.

A really god solution for ads blocking, with a minimal footprint on browser performances was developed by Dan Pollock: with some modifications in the system hosts file, a lot of domains that hosts ads or tracking codes are redirected to 127.0.0.1.

Use this file to prevent your computer from connecting to selected internet hosts. This is an easy and effective way to protect you from many types of spyware, reduces bandwidth use, blocks certain pop-up traps, prevents user tracking by way of "web bugs" embedded in spam,provides partial protection to IE from certain web-based exploits and blocks most advertising you would otherwise be subjected to on the internet.

Simple and effective!

How i can apply the file on my system?

I quote the instruction on Dan Pollocks’ website:

Windows

  • For Windows 9x and ME place this file at "C:\Windows\hosts"
  • For NT, Win2K and XP use "C:\windows\system32\drivers\etc\hosts" or "C:\winnt\system32\drivers\etc\hosts"
  • For Windows 7 and Vista use "C:\windows\system32\drivers\etc\hosts" or "%systemroot%\system32\drivers\etc\hosts"
  • For Windows 8 and Windows 10 use "C:\Windows\System32\drivers\etc\hosts"

You may need to tell Windows Defender to ignore this path (see: http://support.microsoft.com/kb/2764944)
You may have to use Notepad and "Run as Administrator"

Linux, Unix, or OS X

Place the file at "/etc/hosts" or on some systems at "/private/etc/hosts".
You will require root access to do this. Saving this file to "~/hosts" will allow you to run something like

sudo cp ~/hosts /etc/hosts

Furthermore, Christian Bryn has published on GitHub a useful script that automatically update the hosts file on linux systems using the data from http://someonewhocares.org/hosts/:

[embed]https://github.com/epleterte/zerohosts[/embed]

Simple script that fetches and updates your hosts file with zerohost data. It fetches the hosts file from http://someonewhocares.org/hosts/zero/

The fetched hosts file is not modified or easily modifyable in any way as of now. If you modify the result it will be overwritten on update.

The script inserts a BEGIN marker and an END marker. This way updates (re-running the script) will not append the remote file twice — if old data is found it will be removed (using the markers) before the new data is appended.

OS/2

Copy the file to "%ETC%HOSTS" and in the CONFIG.SYS file, ensure that the line "SET USE_HOSTS_FIRST=1" is included.

BeOS

Place it at "/boot/beos/etc/hosts"

Netware

The location of hosts file is Systemetchosts

Macintosh (pre OS X)

Place the file in the Mac System Folder or Preferences folder and reboot. (something like HD:System Folder:Preferences:Hosts)
Alternatively you can save it elsewhere on your machine, then go to the TCP/IP control panel and click on "Select hosts file" to read it in.

Android

Place the file at "/system/etc/hosts".
You will need root access on your device to do this.

Cisco IOS

To convert the hosts file to a set of Cisco IOS commands for Cisco routers use this script by Jesse Baird: http://jebaird.com/blog/hosts-ip-host-generating-blocked-hosts-host-file-cisco-router