*update: Wednesday, 2 March 2016. Switched back to the hosts file from http://someonewhocares.org/ because that one has a more adequate size and therefore much better performance. The file from hosts-file.net uses to much memory if you run a local resolver on your machine.
*update: Wednesday, 17 February 2016 rewrote the script with additional error checks after comment from Peter. Now there is only one script with the hosts file from http://hosts-file.net
*update: Tuesday, 16 February 2016 added another script that also cleans OS X 10.11 DNS caches and uses an even more extensive hosts file from http://hosts-file.net
Recently I compared adblock+, ghostery and a bunch of other ad blocking software in the browsers that I normally use. Most of them blocked ads really well but unfortunately all of them added quite a lot of additional CPU and memory overhead. So, despite the fact that these programs help me to speed up my browsing experience by eliminating advertisements they still slow down my browsing experience.
This evening I did some additional research on the matter of blocking advertisement. I came to the conclusion that host based blocking is the most resource effective way to get rid of ads and malware sites in all programs, not just my browser.
In theory the hosts based method of blocking sites that provide ads and malware is quite simple and elegant.
The /etc/hosts or C:\Windows\System32\Drivers\etc\hosts file lets you override DNS. By re-directing all requests to advertisement and malware servers to 127.0.0.1 or the local loop back interface address of your computer the spam and malware sites become unreachable = no ads or malware.
The problem is that there are literally hundreds if not thousands of sites that are used to spread ads and malware. It is not a trivial task to assemble all of these sites in to a hosts file that is kept up to date.
Fortunately I found http://hosts-file.net that provides extensive hosts files that seems to be updated very regularly.
I gave the optimized file a try and compared it with normal ad blocking software. Blocking results for the sites that I visit seem to be similar to adblocker, ghostery and others software solutions but performance is much better with the hosts file and there is no additional overhead in CPU cycles or memory.
I have decided to ditch ad blocking software for now and made a small shell script that helps me to keep my hosts file updated by just running the script manually or via cron.
The script has been verified on OS X 10.11 and Ubuntu 14.04.3
Please make a backup of your existing hosts file before you try this out and remember that you are the one responsible for what happens to your computer, not me.
# Update /etc/hosts with latest known entries of unwanted hosts
# Thorsten Rhau
# Wednesday, 2 March 2016
# Making sure that we have all needed applications installed
for app in curl killall echo mktemp cat grep
if [ `hash $app; echo $?` -ne 0 ]
echo $app not found, aborting
if [ `whoami` = "root" ]
tempfile=`mktemp` || exit 2
# Downloading data to a temp file
echo -n "downloading new hosts file ... "
curl -LSso $tempfile http://someonewhocares.org/hosts/hosts
# Evaluating curl exit status
if [ "$?" = "0" ]
cat "$tempfile" > /etc/hosts
rm -f "$tempfile"
rm -f "$tempfile"
echo "error downloading the file"
echo "This script needs to be executed as root. Aborting."