Ditching Google - Blocking Tracking With The Hosts File

Author: Steven Neiland
Published:

Warning: This blog entry was written two or more years ago. Therefore, it may contain broken links, out-dated or misleading content, or information that is just plain wrong. Please read on with caution.

Did you know that you are being tracked on the internet? Of course you did, everyone knows google is everywhere these days. How else would you see the same adverts for male pattern baldness follow you around from site to site after you went doing research "for a friend".

Maybe It Is A Big Deal After All

There was a time when I thought this was no big deal. What harm could it really do if google knew what kind of things I was most interested in buying so they could target advertising for me, it sounded like a win/win situation to me. After all they have a code of conduct that states this on the first line of the first paragraph:

“Don’t be evil.”

However after recent (and not so recent) incidents where google has acted questionably in relation to peoples privacy, I have started to limit my interactions with google services. For reference here are some of the incidents I'm talking about:

Now you could make the argument that individually these can all be explained as missteps or simple mistakes, but put them together and you can't help but start to see a pattern that if not evil, certainly is not that good either.

So what can we do about it? Well one step you can do is to opt out of being tracked by google analytics so that google is less able to track your movements on the web. Now you can download plugins for your browser that can do this for you such as Ghostery (which I personally like a lot), but if you don't want to install a plugin these is a really simple way of doing this using the hosts file.

Modifying Your Hosts File To Disable Google Analytics

All the major consumer operating systems have a hosts file which they use as a first point of reference when looking up a web address. Only if an address is not found on this file does the computer then go out to DNS servers to try and resolve a url to an ip. We can leverage this file to block google analytics from tracking us.

As the google analytics code runs from our browsers on our computers it uses the same hostname resolution system to connect to and pass back information to the google-analytics servers. So all we need to do to block this is put in an entry in the hosts file to misdirect it.

To edit the hosts file open notepad (with administrative privileges) and open the file. Note that the hosts file does not have a file extension so when you are browsing the "etc" directory with the file open dialogue make sure that you are showing all files and not just ".txt" files.

C:\Windows\System32\drivers\etc\hosts

With the file open copy in these two entries. These tell your computer that the google-analytics domain is actually hosted on your own computer so that when the analytics javascript code tries to connect to the analytics servers the traffic is misdirected to your computer. The first entry is for regular websites with google analytics installed and the second covers ssl secured websites. Save the file and you are done.

127.0.0.1       www.google-analytics.com
127.0.0.1       ssl.google-analytics.com

Note: While this method tackles the google analytics tracker it does not deal with other systems which may have tracking built in such as addsense or google search itself. This is just one small step down a long road.

Update: I have discovered that windows defender has been deleting the false hosts entry file. I had to disabled it to keep my changes between reboots. Other antivirus programs may do the same.

Yes I Am A Hypocrite

Finally one word about my own website. Yes I am a hypocrite. Anyone who has a bit of tech savvy (basically anyone who is reading this) can see from my source code that I actually have google analytics code installed on this site at the time of writing this entry.

I do have plans to replace it my own analytics system which will read from my server logs but at the moment I don't have time to finish it. So for the time being I'm keeping it as does provide me with some useful information, but hopefully not for too much longer.

Related Blog Postings

Reader Comments

al nonymous's Gravatar
al nonymous
Sunday, February 17, 2013 at 9:15:33 AM Coordinated Universal Time

for some reason i can't block google any more from the hosts file. fw months ago searched for all the entries necessary to block google, twitter, facebook and i still block direct access to twitter and facebook but somehow google gets by. i probably have 50 entries to try to block google and its adsense and 25 or so for both facebook and twitter. would be nice if someone knew how to drop them off the internet permanently.

Steven Neiland's Gravatar
Steven Neiland
Sunday, February 17, 2013 at 9:18:01 AM Coordinated Universal Time

The only other thing I can suggest is the "ghostery" plugin for FireFox.

humb aba's Gravatar
humb aba
Friday, November 22, 2013 at 5:32:56 AM Coordinated Universal Time

a bit dated now, but as i stumbled bout this i can leave a comment at least =)
google seems to have millions of servers, all named like '<crazy_pattern>.1e100.net'
even when opening firefox without ever typing in an url TCPview clearly shows that google messed up firefox!

nice article to avoid using & spread awareness (>_<) about google

A's Gravatar
A
Thursday, November 28, 2013 at 10:11:20 AM Coordinated Universal Time

What about the rest of Google? I don't want ANYTHING Google. Do you have a comprehensive list, including Youtube, Gmail, Search, Play, etc?

DustT's Gravatar
DustT
Monday, November 2, 2015 at 9:36:27 PM Coordinated Universal Time

I have blocked thousands of google, facebook, and other trackers using dead end 0.0.0.0 . This has been working but they automatically change address that way. I am going to try to make a redirect to 127.0.0.1 as your suggestion. But I am going to try and do it in to a dead end. Currently my hosts file is 80MEGS and takes a long time to load, hopefully after I edit the hosts file it will end up more effective and a lot smaller. I also suggest using duckduckgo as your default search engine.
The net is at least 100 times faster with all the trackers blocks, well some of them anyway..

Werner Eissler's Gravatar
Werner Eissler
Tuesday, November 17, 2015 at 12:40:12 PM Coordinated Universal Time

Hello! I use the Hosts file to speed up my internet connection. My computer is a Windows 98 machine from 1999 running the newest Netscape as a browser(from 2008).
You can start with my Google entries that I post below. But you have to maintain your own list, as websites change.

127.0.0.1 www.google.de
127.0.0.1 www.google.com
127.0.0.1 google.de
127.0.0.1 google.com
127.0.0.1 www.google-analytics.com
127.0.0.1 google.de
127.0.0.1 google.com
127.0.0.1 plus.google.com
127.0.0.1 plus.google.de
127.0.0.1 play.google.com
127.0.0.1 googletagservices.com
127.0.0.1 googletagmanager.com
127.0.0.1 safebrowsing.google.com
127.0.0.1 sb.l.google.com
127.0.0.1 clients1.google.com
127.0.0.1 clients.google.com
127.0.0.1 clients.l.google.com
127.0.0.1 safebrowsing-cache.google.com
127.0.0.1 support.google.com
127.0.0.1 fonts.googleapis.com
127.0.0.1 ajax.googleapis.com
127.0.0.1 apis.google.com
127.0.0.1 accounts.google.com
127.0.0.1 google-public-dns-a.google.com
127.0.0.1 ssl.gstatic.com
127.0.0.1 www.gstatic.com
127.0.0.1 csi.gstatic.com
127.0.0.1 pagead2.googlesyndication.com
127.0.0.1 partner.googleadservices.com
127.0.0.1 googleadservices.com

Tom's Gravatar
Tom
Saturday, November 21, 2015 at 6:10:40 PM Coordinated Universal Time

Still like using google. I have used a host file like this for years. Problem I have is manly sites will not open.

  • Please keep comments on-topic.
  • Please do not post unrelated questions or large chunks of code.
  • Please do not engage in flaming/abusive behaviour.
  • Comments that contain advertisments or appear to be created for the purpose of link building, will not be published.

Archives Blog Listing