Other Stuff

Hosts File: Block Ads and Malware

Have you even wonder where all the malware, ads, spyware, junkware, viruses, trojans and worms floating on the Internet comes from? Well they come from tens of thousands of different hosts spread throughout the globe!

The exact number and name of these hosts is of course unknown, but many on the Internet developed the good habit of documenting these hosts in an effort to block them. Many modern browser such as Chrome, Firefox and Safari (not IE, do not use IE/Edge!) have plugins and extensions like AdBlock or AdBlock Plus that can help to filter the scourge out of your experience. But they are only effective as the lists of rules they use, and many websites tend to block the ad blockers these days. So as a complimentary solution we can edit our hosts file.

How To Block Hosts

All modern operational systems have a hosts file that functions as an internal name resolver. It actually maps hostnames to IP addresses, so we can add the junk to it and map to no ip address, like 0.0.0.0. This way every time the browser (or anything inside the system) tries to access a particular blacklisted domain (to grab the virus, ad, spyware, etc) it will fail immediately and you will be spared from a ton of junkware.

The Remedy

To this end MTeam7 gathered and compiled a super huge list of more than 160 thousands blacklisted hosts that can inject those pesky malware into our machines. The list also contains tens of thousands of hosts that have the sole purpose of delivering annoying ads to the pages you visit. Also in the list we included hundreds of intrusive telemetry hosts that exist only to spy on you and on your browsing habits.

How

I will assume that those using linux don't need any further help to install this hosts file. For those that do need help, well it is very simple!

First of all you'll need to be logged in with administrative permissions (admin account). Open the path below (Windows, Unix-Like), make a backup of the original hosts file present there (in case you want to "uninstall it") and copy this hosts file in it's place (overwrite it).

Mac users can jump to that folder by pressing CMD+SHIFT+G and pasting the path below.

Hosts File Path

Unix-Like System:

/etc/hosts

Windows System:

c:\windows\system32\drivers\etc\hosts

Final Thoughts

That's it! If you have problems with a particular domain, for instance if the dirty little website you are accessing forces you to see the ads to show you the content, you can simply remove that line out of the file (you'll have to examine the html to see the host name) or simply put the original back. Or ban that website from your life... that's what I do.

Of course you'll need to edit this file to suit your needs. Some services you may use might be in the list, so if you wish you'll have to remove them manually. So, tweaking the list is imperative, or...

You may also like to use the hosts files with the companion sh controller script. Check our bashrc example.

I am from a time when ads use to be the size of thumbs, and not intrusive. Indeed the web has become a dirty place, but this trick makes things a little better. Enjoy!

Download Hosts File