20 January 2012

How To: Use the hosts File to Avoid Ads and Speed Up Browsing

I went to the Samsung.co.uk website today and was greeted with a blank page and “waiting for platform.twitter.com” in the status bar for some time. This happens on many pages where the page is waiting for content from another site, which is slow to respond. Twitter in particular has a history of many load issues (see the Wikipedia Entry, Outages section).

In order to avoid these on your computer you can effectively tell it to ignore requests for certain URLs in Windows by adding them to your hosts file. On a Mac or Linux it is also possible using a different method (e.g. using Iptables) although that is outside the scope of this post.

Suitable hosts files can be found here.


  1. edit /etc/hosts as admin e.g.
    sudo vi /etc/hosts
  2. Paste in the bad hosts


  1. Open Notepad as an administrator (Start, type Notepad, once selected press Ctrl Shift and Enter simultaneously)
  2. Select File, Open (Alt F, O) and browse to:
  3. C:\Windows\System32\drivers\etc\
  4. on a Windows 7 machine, other versions might use a slightly different path.
  5. Change file type to “All Files”:
  6. Open hosts
  7. Add the bad hosts at the bottom e.g.: platform.twitter.com
  8. Save and exit.

How it works
Operating systems consult the hosts file when resolving domain names, and entries there override those obtained from the DNS server. This entry basically says for the URL “platform.twitter.com” go to which is the local machine i.e. nothing.

Create a Shortcut To Edit Hosts
If you want to alter the file regularly the operation above can become a bit tiresome so I like to create a short-cut:
  1. Show the Desktop by pressing Windows key and D
  2. Click Start, start typing Notepad and when it appears in the list right click on it and drag it to the desktop. This will bring up a menu. Select Create Shortcut.
  3. Right click on the new shortcut and choose Properties
  4. In the Shortcut tab append a space and the path to the hosts file in the target field, so mine ends up looking like:
  5. %windir%\system32\notepad.exe C:\Windows\System32\drivers\etc\hosts
    NB: It might throw a “name specified not…" error here: see earlier post.
  6. Click Advanced and select "Run as Administrator".
  7. Click OK twice and try out your new short-cut. It should bring up the hosts file ready for editing (and possibly an administration confirmation).

1 comment:

  1. Phil -
    Thank you so much for this insight. It has been a pain for the last several days. Now I am back up and accessing all of my regular sites.
    Jim Lindell