The user has to be an administrator to do this.
Open Start menu navigate to All Programs > Accessories, right-click notepad and click “Run as administrator“.
Go to File > Open and type the following path in the dialog box that appears
Add the following lines to the end of the file on a newline.
127.0.0.1 google-analytics.com 127.0.0.1 www.google-analytics.com 127.0.0.1 ssl.google-analytics.com 127.0.0.1 www.ssl.google-analytics.com 127.0.0.1 statcounter.com 127.0.0.1 www.statcounter.com 127.0.0.1 c.statcounter.com 127.0.0.1 www.c.statcounter.com
Save the file and close notepad. Clear the DNS cache by going to Start > Run, type “cmd” and enter the following command.
Even though this step isn’t mandatory it is better to do it.
The user must be root or have sudo permissions to edit this file.
Open the command line (use the shortcut CTRL+ALT+T if on GUI) and enter the following commands, if you’re a non-root user with sudo privileges add the “sudo” keyword.
echo "127.0.0.1 google-analytics.com www.google-analytics.com ssl.google-analytics.com www.ssl.google-analytics.com statcounter.com www.statcounter.com c.statcounter.com www.c.statcounter.com" | sudo tee -a /etc/hosts
Clear the DNS cache by entering the following command
sudo /etc/init.d/dns-clean restart
If you want to block Google analytics and statcounter in your office instead of editing the editing the hosts file on each and every system a DNS zone can be created for these domains in your internal DNS server as below
@ A 127.0.0.1 www A 127.0.0.1 ssl A 127.0.0.1 www.ssl A 127.0.0.1
@ A 127.0.0.1 www A 127.0.0.1 c A 127.0.0.1 www.c A 127.0.0.1
This will ensure privacy in your organization.
What does all this do ?
If you’re the curious type who likes to know what is happening behind the scenes read on.
The purpose of the domain name is to make it easy for humans to remember website names but for computers to access them IP addresses are needed. So each domain name like “google.com”,”yahoo.com”,”websistent.com” is mapped to an IP address. When you type a website name in your browser’s address bar a protocol called DNS “resolves” these domain names to an IP address and it following these steps in priority from top to bottom.
- Check the hosts file for a static entry
- Check the DNS cache of the operating system
- Ask the ISP’s DNS server
If it gets the IP address in step 1 or 2 it doesn’t proceed further.
But wait a minute what if a webmaster self-hosts these tracking code, will I be tracked ? No. In this case the code will load but it will NOT be able to send your information to its servers (read Google Analytics or Statcounter).
Have a doubt or having trouble getting this work, drop a comment below and I’ll help you out.
I was wondering how I would know if it is working? When I go to statcounter I still see myself.
If you’ve correctly edited your hosts file you shouldn’t be able to open statcounter’s website. Make sure you’ve added all the URLs specified in this article.
You can check this by opening the command-line and pinging the following URLs
You should get replies from 127.0.0.1
Jason Long says
Thank you very much this worked excellently! I will be doing this on all windows machines I have.
hello. i have a statcounter account and i still want to track other’s isp who views my blog (in short i still want to access my statcounter account). but i dont want other people to track me when i view their blog. is this possible even if i do this (your instructions)? i am using windows btw.