Hosts File: Block Ads and Malware
Have you ever 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 and because of this we can add the junk hosts 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 it will fail immediately sparing you from a ton of junkware and headaches.
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 as well as hundreds of intrusive telemetry hosts that exist only to spy on you and on your browsing habits.
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, make a backup of the original hosts file and copy this hosts file there.
Mac users can jump to that folder by pressing CMD+SHIFT+G and pasting the path below.
Hosts File Path
macOS / *nix Systems:
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 what that host name is) or simply put the original back. Or ban that website from your life... that's usually 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 but you can always remove them manually in order to access the site in question.
If you are using Linux or macOS you may also like our
sh controller script. You can find it in the Simple bashrc page. Look for the
hosts function in it.
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!