Windows Hosts File Optimizer

Martin Brinkmann
May 23, 2010
Software, Windows, Windows software
|
9

The Windows hosts file is used to map hostnames to IP addresses forcing the computer to use that mapping instead of the one provided by the DNS server. This can be useful in several situations like speeding up Internet surfing or making sure that a website is working fine after moving it to another Internet server before the new IP has propagated.

The Windows hosts file is basically a text document that lists IP addresses on the left and hostnames on the right. The hosts file is located in system32/drivers/etc/ of the Windows folder. It can be edited with any text editor.

Optimizing the hosts file can speed up the parsing of the file and keep the DNS client service enabled while using a big hosts file.

The hosts optimizer will automatically remove duplicate host names from the hosts file, remove all comments including entries that have been made a comment to disable them and put a maximum of nine host names in a single line if they point to the same IP address.

The program will automatically created a backup of the hosts file before optimizing it. It has to be noted that the DNS cache needs to be flushed whenever a change is made to the Windows hosts file if the DNS Client service is enabled.

Hosts Optimizer can be downloaded from the abelhadigital forum. The program is also part of the hosts manager HostsMan.

Advertisement

Tutorials & Tips


Previous Post: «
Next Post: «

Comments

  1. eladkarako said on January 7, 2022 at 10:07 pm
    Reply

    you should be aware that above some amount of entries in the HOSTS file, the Windows DNS cache service hogs a lot of CPU. this happens every-time the cache is being updated, after the HOSTS has been updated or the ipconfig command flushed the dns cache (for example). up until windows 7 the solution was to simply disable the DNS cache service, it worked really well, and you had a perfectly working OS. I had 40MB+ hosts w/o a problem, and it worked really well. Windows 10 (a huge crapware from some aspects but due to poor TLS support, and hardware limitations on new systems I had to upgrade) actually had the dns-cache service links in such a way the disabling it (you boot to safe mode and use autoruns by sysinternals to local and disable the checkbox of the service) makes accessing shared folders from other resources on the same network unavailable, that means folders files over the samba protocol was no longer possible, not even using an IP!!! which made no sense! so now I limit my entries and instead use adguard dns in my router as a first line of blocking, and in my windows peerblock, which is kernel driver based, that blocks various lists by IP. I would rather had my ton of HOSTS (github.com/eladkarako/hosts) but I can’t..
    I did got the new raspberry pie w2 with integrated wifi,
    after installing the lite linux os on it,
    I can make it into a proxy with actual filtering, and set my router to pipe through it for every connection, it should enable even blocking by the path of the url (not just a domain-based blocking which is what HOST file or a dns server, or ‘pi-hole’).

    https://www.howtogeek.com/683971/how-to-use-a-raspberry-pi-as-a-proxy-server-with-privoxy/
    this makes possible to block youtube ads which have somewhat of a complex matching patterns, that would only possible to block using ublock rules and something like that:
    https://gist.github.com/eladkarako/7ee77942acc066f930de0268c387239e#file-block-youtube-ads-md

    if you know of any workaround for the windows 10 ‘thing’ please share..

    anyway..that’s just f.y.i. if you had some CPU spikes after editing your hosts file on windows..

  2. Deba said on April 1, 2011 at 4:56 pm
    Reply

    can anybody provide a direct link to download host optimizer

  3. Jojo said on May 24, 2010 at 8:18 pm
    Reply

    1. In the past, IE apparently had problems with large hosts files created by Spybot, apparently resulting in problems opening IE (either slow or would not open at all). I personally haven’t seen this problem in a while, yet I have a large hosts file, so it appears that the problem was with IE and not the size of the hosts file.

    2. There is a good write-up on hosts file here:
    http://vlaurie.com/computers2/Articles/hosts.htm

    3. This site says that you CAN use wildcards:
    http://www.ezlan.net/host.html

    So:
    127.0.0.1 *.sitename.com

    SHOULD be equivalent to the two entries of:

    127.0.0.1 http://www.sitename.com —AND—
    127.0.0.1 sitename.com

  4. Jojo said on May 24, 2010 at 8:39 am
    Reply

    I looked at the hosts file tonight.

    I don’t use it myself, but Spybot Search & Destroy does. What I noticed is that Spybot inserts TEO entries for every address in the file, one with www in front and one without. Like this:

    127.0.0.1 http://www.onj
    127.0.0.1 onj
    127.0.0.1 http://www.pu
    127.0.0.1 pu
    127.0.0.1 http://www.yes
    127.0.0.1 yes
    # End of entries inserted by Spybot – Search & Destroy

    Is it really necessary to do what Spybot is doing?

    Obviously, there are twice the number of addresses to process using their methodology which probably slows down anyone doing lookup’s in the hosts file.

    1. Martin said on May 24, 2010 at 9:51 am
      Reply

      I had to edit the domain names. Lets look at http://www.ghacks.net as an example. .net is the top level domain, ghacks is a subdomain of that and www is a subdomain of ghacks. Both http://www.ghacks.net and ghacks.net are independent from each other. Most webmasters redirect both to the same domain but that does not have to be the case. About the hosts file. I actually have not tried it if entering example.com is sufficient to block all requests to subdomains as well. I think I remember that the hosts file supports wildcards, e.g. *.example.com to block everything from a domain which means my guess would be that the hosts file only blocks the hostname that is shown and nothing else. But I have not verified that.

  5. Sérgio Dias said on May 23, 2010 at 7:44 pm
    Reply

    I ended up with 50% CPU usage from svchost.exe because of this. Thanks, but no.

    1. adam said on February 26, 2021 at 6:29 pm
      Reply

      correct.a huge merged hosts file is going to take up some memory unfortunately….I’ve decided to use the pi-hole.net approach personally….the little raspberry pi now uses my pi zero as it’s DNS server….

      curious though is there such a tool to check to see if this huge list of hostnames is actually valid? some of these hosts files I dont feel actually get validated….

  6. Maik said on May 23, 2010 at 5:47 pm
    Reply

    HostsMan is a brilliant little freebie!

Leave a Reply

Check the box to consent to your data being stored in line with the guidelines set out in our privacy policy

We love comments and welcome thoughtful and civilized discussion. Rudeness and personal attacks will not be tolerated. Please stay on-topic.
Please note that your comment may not appear immediately after you post it.