Question Changing hosts file blocks internet

Status
Not open for further replies.

BobCharlie

Distinguished
Sep 2, 2011
221
1
18,710
Win 11, hp envy 360 laptop, I just bought. Was fully oem far as I can tell, and even reverted it back just in case as it was purportedly refurbished.

Tried using an ad/malware blocking hosts file, rebooted, and internet blocked. Once blocked, have to go into safe mode to revert/remove that hosts file (says it's being used by another program otherwise). Tried a different hosts (Steven Black) and same thing, internet blocked.

I switched to Tinywall and avast, thinking a default win 11 program was enforcing a block, and now changing hosts locks Tinywall and it'll enter "unknown mode" with a white shield icon, and eventually state it can't connect to tinywall services.

I have an old win 7 laptop, with Tinywall and avast, and an older hosts list I succcessfully changed. So I tried adding the newer Steven Black ad blocking hosts and exact same deal, it blocks internet and basically causes tinywall to have a soft-lock and crash? Internet IS available/connected on BOTH laptops, but is getting blocked by something. I noticed it doesn't seem to like it when I reenable "Prevent Modifications to hosts list" in tinywall and will add a 0 kb hosts file if it's removed.

I tried a custom hosts file with literally 2 ad domains blocked, and everything was OK. Tinywall was fine and booted into normal protection, internet was working? But a full list and nothing?
 

BobCharlie

Distinguished
Sep 2, 2011
221
1
18,710
It would seem the size of the hosts file is possibly the issue. Old hosts on win 7 was around 800kb. SteveBlack hosts is 6.75mb. Other one from Lightswitch05 is 14.5mb.

After letting the newer laptop idle for awhile, tried changing tinywall back to normal mode again and it actually worked. Tried a site that forces ads and they were blocked.

Seems it takes so long to load these newer hosts files that it blocks internet access until it can fully do so, which is why I couldn't remove hosts file as it was still running through it. Suppose it's like opening a giant text file in notepad.

Super surprised I couldn't find anything online.
 
Any hosts file larger than 135kB will slow your internet some, but up to 500kB still works tolerably even with DNS cacheing service enabled. The larger it is with the cacheing service enabled, the longer that svchost will go to 100% CPU on each bootup and prevent you from using the internet until it's finished.

To disable DNS cacheing service open the "Services Editor":
Start | Run (type) "services.msc" (no quotes)
Scroll down to "DNS Client", Right-click and select: Properties - click Stop
Click the drop-down arrow for "Startup type"
Select: Manual (recommended) or Disabled click Apply/Ok and restart.
Disabling the service hammers the DNS server with many more requests though because there isn't a local copy

Moral: for a very large hosts file, put it into the gateway router, not the client machines (where Windows 10 can ignore it if it likes anyway). Sure the router CPU is slow, but it's always-on and the hosts file only needs to be parsed into memory once
 
  • Like
Reactions: Grobe

BobCharlie

Distinguished
Sep 2, 2011
221
1
18,710
I tried the 800kb hosts from the win 7 laptop on the new win 11 laptop, and no issues. Tinywall worked correctly, verified a site it was known to block ads from are being blocked, and loading seems close to normal. So it seems reaffirm an issue with file size.

EDIT: Posted w/o seeing the above post.
 

BobCharlie

Distinguished
Sep 2, 2011
221
1
18,710
Thanks BFG-9000. Really surprised the read.me's for these newer hosts projects are not warning about the size being an issue.

Is there no way to speed up the svchost? Is this one of those legacy programs MS never bothered to update? Is this an issue on Linux builds? Or are they even capable of blocking?
 
svchost has been sped up. See, until recently, all those hosts files pointed to 127.0.0.1 (home) so for each entry svchost had to look on your local computer for a server and wait until it timed out before going to the next entry to make sure there wasn't one there. 0.0.0.0 that is used now is quicker as by definition it's an unroutable address, but svchost still has to go through each line to verify no server can be there when generating its cache.

Each line is now blazing fast but if you use a hosts file with 500,000 entries it's still going to take some time. If cacheing is disabled then svchost doesn't go look until you actually try to access that address. So instead of a big upfront delay on boot, there are very small delays for each DNS lookup.

That's why I suggested putting adblock and the hosts file into the router--it may be slower to come online if ever rebooted, but you don't do that often, plus there it can protect things like Android devices that don't natively support hosts files. BTW routers almost all run linux, and their own dnsmasq DNS cacheing service would have to do the same thing as svchost so isn't going to be any quicker, especially because the CPU is slower. But again, always-on means you'd only have to wait once
 
I suspect this is because the host file is treated differently than DNS. Host file is mostly not used on most machines they may not have ever optimized the code, microsoft is too busy adding other garbage to windows.

You would think there would be no issues doing this on your pc when people do the same thing with a raspberry pi running pi-hole. It is running a dns server function but is still a black list of sites similar to the host file. The added advantage is it can block ads on platforms that you can't load a host file into.
 
By default, linux clients like on Ubuntu don't cache DNS entries unless you go install something like ncsd. So by default Ubuntu will hammer the DNS server just like Windows with the DNS cacheing service disabled. So the steps I suggested will make Windows work like linux.

If you setup linux to use a hosts file for DNS cacheing in the same way, then it will have to do the same things Windows does and take pretty much just as long to do so. Which could be worth the long wait after bootup to avoid all the little latency penalties from running uncached if you are aware of the tradeoff, but result in many more support questions so is not the default behavior.

As people like their computers to just work, Microsoft have taken steps to "protect" the hosts file and now you have to jump through many more hoops to change it. Because the default way Windows hosts works is just fine until someone decides to use a 15MB file there, the hoops are an "are you really sure you want to do this" reminder
 
Status
Not open for further replies.