Archive

Posts Tagged ‘hosts’

Block Advertisements in ANY Browser via /etc/hosts

May 15th, 2009 22 comments

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.orig

sudo 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.

User Feedback – /etc/hosts explained : Ubuntu (5.10 / 6.06.1 / 6.10)

December 5th, 2006 1 comment

One of you contacted me recently with a few questions regarding my previous post, Network File System (NFS) : Ubuntu (6.06.1 / 6.10). I wanted to post some follow up information on that to help clarify a few of the steps. Some of this may be very simple for many of you, for others it will hopefully open your eyes to a few more powerful aspects of an Ubuntu Linux system. Here goes.

Question: How did you modify the /etc/hosts file to use the ‘media’ shortcut?

Editing the /etc/hosts file is really simple and you can do quite a bit with it. Ever wish you could simple visit “mysite” in your browser and it’d know where you wanted to go? Ever wish you could give nicknames to your local network machines instead of trying to remember the IP address? Here is the place to do it.

To edit the file you would want to use a quick command within a terminal:

sudo gedit /etc/hosts

Simply add a line to your /etc/hosts file to create a network shortcut using the following syntax: ip.address shortcut. Example (on my network):

127.0.0.1 localhost
127.0.1.1 notebook.local notebook

192.168.0.3 media
192.168.0.8 silverbox
192.168.0.2 blackbox

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

The three lines in italics are my additions. You can use the same syntax to update your /etc/hosts file and go wherever you want! The above is an example of using a shortcut for the local network but the same goes for the outside world. Try something like:

google.com 42
ubuntu-tutorials.com bestsiteever

…and the next time you type “42″ in your browser it’ll come right up with google (yes, the answer to life, the universe and everything!), or put in “bestsiteever” and come right back here for some more great tutorials!

Categories: Linux Tags: