Saturday, July 27, 2013

Speed up internet browsing by skipping server side DNS lookup and blocking unwanted ads

Use Hosts file to speed up browsing

The title says it all. Page load speed can be increased if only host name resolution can be done within your computer and you don't have to wait for all the ads in a site to load.

In a previous post, I mentioned that you can increase browsing speed (page load speed) by using other DNS servers like Google Public DNS and OpenDNS instead of using your ISP's DNS service. This is because your ISP may be over saturated that it is having difficulty coping up with all the requests.

But using Google Public DNS or OpenDNS  is still in the internet and so you still need to go through it to resolve a host name.

But there is a way to resolve host names within your local machine. In the old days, host name resolution is done by using the Hosts file (this file has no extension). This file resides in:

C:\Windows\system32\drivers\etc\

The Hosts file is a simple text file that contains IP address with its corresponding host name. It maps a host name to its corresponding IP address. We can read and edit its content by using a text editor like Notepad.

How to add a host name and its corresponding IP address in the Hosts file?
If you open your Hosts file now in Notepad, you will only see one entry for localhost, 127.0.0.1     localhost also called the loopback address.

The format for adding to the list is the IP address first, then a space and finally the host name. It does not matter if you have one, two or as many spaces between IP address and host name as the succeeding spaces will be ignored but for readability everyone use the tab.

If for example then we wanted to add www.google.com using the IP address 74.125.128.191 (one of many Google's IP address). It would look like this: 74.125.128.191     www.google.com and if I decided to add one for this blog: 74.125.128.132     cyberliving.blogspot.com. The content would then look like this:

# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

127.0.0.1       localhost
74.125.128.99 www.google.com
74.125.128.191 www.blogger.com

Save this file. Please note that notepad automatically adds extension to saved files so do not use Save as... just use Save to preserve the property of the file.

Once the file is saved, the effect of it is immediate. There is no need to restart or disconnect/connect to the internet. While using Chrome version 28, it is not necessary to restart the browser as well but some browsers may require restarting.

Guides to Host file editing
Here are some rules that must be strictly followed in order that you will not wreck havoc with your networking.
It is recommended that you back-up your Hosts file before you edit it. Just create a back-up folder within the C:\Windows\system32\drivers\etc\ folder then copy the Hosts file and paste it inside the created back-up folder.








  1. Each entry should be kept on individual line. One IP address and host name per line. If a host name has more than one IP address, then add it in another line with again its host name.
  2. IP address is placed in front of the host name separated by at least one space.
  3. Do not associate host name with any programs. Watch out when opening the Hosts file as you might accidentally associate this with a program like Notepad. Never click the "Always use the selected program to open this kind of file" radio button to avoid this.
  4. When saving, just click on Save and not Save as... to avoid placing an extension to the file. Notepad and other programs automatically ads the default extension when Saved as... is used.

To block a site or ad from loading
In order to do this, give the host name where the ads are coming from or the site you wish to block with the localhost IP address (127.0.0.1)

Benefits of using the Hosts file
By using your machine to look-up sites, it will be much faster for it to resolve their host names and consequently land to the page faster.

Blocking ad sites from loading will also make the page you are trying to visit load up faster. The downside though is that you will see some content of the site not loading or with an error message.

Blocking some malicious sites containing malware or trojans (or phishing sites) will protect you from accidentally landing on them thus preventing you from downloading said malware and/or trojans. You will also be prevented from entering phishing sites thus your username and password is protected.

Back to CyberLiving home page

Other Posts

2 comments

Unknown August 5, 2013 at 3:47 AM

I can't thank you more for giving the solution to block ads. I have been really annoyed from anytime ads popping up on my computer screen, disturbing my internet surfing.

Regards,
Silvester Norman
Change MAC Address

J August 7, 2013 at 5:15 PM

Hi Silvester, you're welcome. I understand completely what yo mean. I specially dislike those pop-ups on page load. Five years ago, I would close the page immediately because that was how I got infected by a trojan before, clicking the "close" word of a pop-up.

Post a Comment