Block Advertisements in ANY Browser via /etc/hosts
->
I have been getting more and more tired of Firefox lately. Tired of the bloat. The unreliability. The gecko engine. I’ve been tinkering with alternate browsers such as Midori (which is *great*, assuming you can get >=0.1.6), Arora and Chromium. I think WebKit is the browser engine of the future, and with these browsers it is nearly a reality. They are still a little rough around the edges, but I can honestly see one of them absolutely taking off by the end of this year. Firefox, prepare to be dethroned!
The one missing link in most users transition to a new browser however is their reliability on extensions. I know I have a few extensions that I really don’t like to live without. I bet you do as well. Let me guess what your number one extension is? AdBlock Plus? So, if these new browsers don’t have an extension architecture (yet), how can I block ads? You can use your /etc/hosts file.
Let me tell you, quickly, about the /etc/hosts file for those that may not be familiar. The /etc/hosts file is the predecessor to the DNS system that we use now. It is a local mapping of IP address to hostname. At this point, as we now rely on DNS, the /etc/hosts file is generally pretty empty. You’ll likely just have entries that make sure your machine can find itself by localhost or hostname. Something along the lines of:
127.0.0.1 localhost hostname
Now, you might be thinking “How am I going to block all the internets advertisements if my /etc/hosts file looks like that?” Well, you won’t, if it just looks like that. I have a solution for you though, and it requires very little work on your part.
In searching for a solution I have come across an /etc/hosts file that is (minus comments) 15,169 lines long. That’s right. Fifteen thousand one hundred sixty nine lines long. That is a lot of mapped IP addresses! What someone has done is collect every nasty thing he could find into the hosts file, and map it to 127.0.0.1.
What does that actually mean? It means that anytime your browser is told to display an ad it’ll need to look up the address. The /etc/hosts file is checked first before DNS, which then tells it to ask the local machine. The local machine, of course, does not have that information to display and therefore nothing is displayed. Bingo! No more ads.
But wait, there’s more! This not only applies to blocking ads, but also banners, 3rd party cookies, 3rd party page counters, web bugs, and even most hijackers. You’re not only blocking advertisements, you’re outright blocking thousands of known problematic and malicious websites. And all this without requiring a single Firefox extension. It works in ANY browser.
So, I hope you’re wondering where you can get a copy of this magical file that solves all of the worlds woes. Well you can get it here of course!
disclaimer: I am not the original author of this file, but it has been published under a CC-BY-SA license and under that license I am redistributing it. Attribution is contained within the file itself.
sudo mv /etc/hosts /etc/hosts.origsudo wget -c http://zelut.org/projects/misc/hosts -O /etc/hosts
These commands will move your original file as a backup and then pull the file from the web, putting it directly where it needs to go. You should be ready-set-protected after completion of the second command. Pull up a browser (hopefully you’ll try something other than Firefox), and give it a try.
If you have anything to add or subtract from the hosts file, you may edit it directly with a text editor. If you’d like to share your changes with the rest of us you may email me your update in the form of a patch. Please make sure your patch is created against the latest version.
I hope this solution works for many of you towards trying out and helping improve alternate browsers. Again, I highly suggest Midori or Arora as GTK or Qt (respectively) WebKit based browsers.