Use HOSTS file to ban ads and speedup DNS lookups

It is much easier to access the Internet when using domain-names like, instead of needing to remember IP-addresses. The conversion of a domain-name to an IP-address is performed by the Domain Name System (DNS) and is also called host name resolution. Your Internet Service Provider (ISP) is responsible for supplying the DNS.

It is possible to divert from the normal domain-name conversion supplied by your ISP, and instead specify your personal domain-name conversion. This is possible because before contacting the DNS, then the computer checks a special file named HOSTS whether it contains the domain-name and the corresponding IP-Address. The HOSTS file is a simple text file, which can be edited a text-editor like Notepad. The HOSTS file allows one to specify your own list of domains and their corresponding IP-Address.

The HOSTS file can be used to:
  • Ban access to certain domains to avoid loading advertisements, thus making the Internet browsing quicker.
    1. Find the domain (The address from where the advertisement is loaded from)
    2. Insert the this dummy IP along with the domain in the file:

    3. If having problems creating the ban file it might help to have this line in the top of the HOSTS file: localhost

    4. There is certain sites that provides pre-made HOSTS file for your convenience (and peril): Note an alternative way to ban advertisement is to use a firewall, as many firewalls includes advertisement blocking functionality, and its list of "bad" domains are updated regularly.
  • Speedup DNS lookups by not needing to contact the DNS server, thus making the Internet browsing quicker.
    1. Find the IP for domain (Can be done by pinging the existing domain)
    2. Insert the discovered IP along with the domain in the file:

    3. There exists utilities to help you maintain your HOSTS files: Note the DNS lookup tweak should only be done for a limited set of frequently used domains (like mail server), because if the domain changes IP address then the domain will become inaccessible.
The HOSTS file is usually found here:
  • Windows 9x = C:\Windows\
  • Windows NT-2000 = C:\Winnt\System32\Drivers\etc\
  • Windows XP = C:\Windows\System32\Drivers\etc\
  • Linux/BSD/Solaris/Unixes = /etc/
  • BEOS = /boot/beos/etc/
Note Win2k/XP/2k3 have a new feature called DNS Client that caches DNS lookups. This makes the DNS lookup tweak unneeded as it is automatically is performed by this new feature. Though there have been several reports that if using a large HOSTS file to ban advertisement, then the DNS Client will introduce slowdowns, and should be disabled if wanting to ban advertisements using the HOSTS file.

Note by default the HOSTS file only contains one active entry and that is " localhost". If having trouble with accessing a domain, then one can disable the HOSTS file effect by deleting or renaming the HOSTS file, and restart the browser(Sometime need to restart the system).

Note lately some hijackers have started to modify the HOSTS file to make redirects to a different site than intended. One can try to "lock" the HOSTS file by changing the file attributes to Read-Only, Hidden, System. If the file is placed on a NTFS partition then change the NTFS permissions for accessing the HOSTS file. Though if the hijacker is clever enough then it will have little trouble going around this "locking".

More Info MS KB972034 - Reset hosts file to default



  1. Moore says:

    I have to say thats not the best advice I've ever seen regarding the use of a Hosts file and the DNS client service..

    For people that are relying on the protection of a Hosts file to block ads, spyware and other malicious sites , the DNS client service shoud be disabled.

    The DNS client service is just another useless service added by microsoft , and will slow your browsing down if left enabled while using a large Hosts file for protection.

    For more information consult the MVPS site which covers the use of a Hosts file in great detail.

    For further information on using a Hosts file for protection see my post here:


  2. snakefoot says:

    I have to say thats not the best advice I've ever seen regarding the use of a Hosts file and the DNS client service.

    I have updated the description for the DNS Client service about the possible conflict with a large HOSTS file.

  3. sanjay says:

    Hi i need to give few sites access only 3 to 4 and want to block all other sites how can i do it or is it possible in host file.

    • Snakefoot says:

      It is not possible to use wildcards in the Windows hosts file, and one would still be able to use an IP-address directly. I would probably setup a Proxy-server, and use that to control access permissions to allowed sites. One could also consider to configure Windows firewall to only allow the IP-address-ranges for these 3-4 sites, but with exceptions for other services like Windows Update.

Leave a Reply

Your email address will not be published. Required fields are marked *