73

Google Chrome is ignoring the settings in C:/Windows/System32/drivers/etc/hosts file. Both IE11 and Firefox are installed on the same machine and work as expected.

I've tried all the solutions I could find online including:

  1. Open chrome://net-internals/#dns and click the Clear Hosts Cache button.
  2. Go in Settings, Show Advanced Settings and uncheck the following three options: (X) Use a web service to help resolve navigation errors (X) Use a prediction service to help complete searches and URLs typed in the address bar (X) Use a prediction service to load pages more quickly
  3. Go in Settings, Show Advanced Settings, click the Clear Browsing Data button, selected Cached Images And Files from the beginning of time, and click Clear Browsing Data.
  4. Restart Chrome.exe.
  5. Restart the computer.
  6. Make sure to add http:// to the front of the web address.
  7. Make sure proxy settings are turned off
  8. Run cmd.exe and run ipconfig /flushdns
  9. Uninstall and reinstall Chrome

I'm at a loss... Is there anything I missed that I can try or check?

5
  • 1
    I have the same problem on Chrome for Ubuntu Linux. I'm using a proxy, and instead of checking /etc/hosts, Chrome prefers to check the proxy's DNS. Mar 16, 2017 at 16:06
  • This just happened to me working with a client. I tested with Firefox and it worked immediately. Dec 5, 2017 at 20:28
  • I have same problem on oracle linux using a proxy on Version 63.0.3239.132 (Official Build) (64-bit)
    – Don
    Mar 14, 2018 at 4:04
  • What is the name of the domain you're trying to access? Aug 16, 2018 at 13:50
  • 1
    Make sure you add both the 'naked' and the 'www' domains as separate entries to the hosts file, and then clear cached redirects: superuser.com/q/304589/143613. That plus restarting the browser did the trick for me.
    – Mahn
    Mar 28, 2019 at 12:24

14 Answers 14

40

Seems that Chrome doesn't likes the following extensions for that kind of stuff:

.dev
.localhost
.test
.example
.app

Use .local and the problem seems to disappear.

5
  • 3
    Include .app too! Sep 23, 2018 at 18:13
  • This worked for me. I changed to .local (from .localhost) and Chrome was happy to follow etc/hosts. After some research, it looks like that's intentional behavior. However, I'm really confused how all my coworkers in my office are not experiencing the same behavior with the same version of Chrome. It seems like there has to be a way to get .localhost to work. Jan 22, 2019 at 16:52
  • I use .local but Chrome still ignores the hosts file.
    – theking2
    Feb 2, 2021 at 14:17
  • 1
    Same happens with Firefox in certain Linux distributions, eg. in Ubuntu 20.04 I don't have problems using *.localhost domains, but in Xubuntu 20.04 either Chrome or Firefox don't accept connections from these domains, and changing to *.local solved the issue in both browsers. May 11, 2021 at 14:25
  • 1
    I don't understand what is .localhost and .local here? In my hosts file I mention 127.0.0.1 youtube.com to block youtube. Where is .localhost to be mentioned?
    – KurioZ7
    Aug 24, 2021 at 14:18
24

If anyone stumbles on this problem in 2021, for me the fix was to disable Use secure DNS option from chrome settings. After disabling that, all the options in the hosts file started working.

The option is located under Privacy and Security > Use secure DNS

Link to get there faster:

chrome://settings/security

3
  • 2
    This is the correct answer to this problem. "Secure DNS" is a euphemism for DNS over HTTPS (DoH). It is enabled by default now and it causes the browser to ignore all local DNS settings and do its own DNS lookups using a provider configured in the browser (by default probably Google) over a secure HTTPS channel. This will prevent eavesdroppers or your ISP from tracking what sites you visit by monitoring your DNS lookups, but gives that tracking ability to the DNS provider specified by the browser. Feb 10, 2022 at 10:25
  • 2
    I actually want to use the DoH feature and also be able to use the local DNS only for developing my application. Is there any workarounds for this on Chrome or is it not possible? Sep 24, 2022 at 5:00
  • This worked for me, and the good thing is, i could just enable it after wards again, cause i dont want the DNS from my provider, so just disable it, load the desired page once and reenable it.
    – FlexXx
    Jun 27 at 8:28
15

This has been identified as a "bug" in Chrome, but it appears to be absolutely intentional behavior. Google Chrome does not honor /etc/hosts when connected to the Internet. It always does a DNS lookup to determine IP addresses.

While my references below mostly relate to my expereinces with this on Linux, it is not confined to Linux.

https://groups.google.com/a/chromium.org/forum/#!topic/net-dev/iKXqyc40tW0

https://superuser.com/a/887199/75128

https://bugs.chromium.org/p/chromium/issues/detail?id=117655

5
  • 1
    I'm on linux and the solution in google groups worked for me. Thanks!
    – Baha
    Dec 1, 2019 at 16:37
  • Second the above comment, I tried most of the solutions listed here and elsewhere without luck initially (on Windows 10). It's the next day, and Chrome seems to be respecting my hosts file. I've seen a lot of sites stating that Chrome doesn't respect etc/hosts but it isn't strictly true. Mar 21, 2022 at 12:20
  • 2
    @haymansfield Wireshark tells another story. I have actually seen Chrome making DNS requests for items that were in my hosts file. It was not honoring /etc/hosts and rather making a DNS request when there was a network connection. Without a network connection (Pulling the ethernet cable, or turning off WiFi), Chrome would honor the hosts file. When I discovered this in Linux, there was a config option that could be used as a workaround. That option was removed. This is most definitely a bug. Actually read the notes of the Chromium bug report. Mar 22, 2022 at 17:31
  • @karl-wilbur Apologies, I make no judgement on Linux, I'm purely talking about Windows 10. Mar 23, 2022 at 8:54
  • Hi guys, it started happening on Windows 10 for me this week. :(
    – vothaison
    Nov 13, 2022 at 3:42
10

Okay I faced the same problem but then I found the solution. Try this: Go to history (Ctrl+H) -> In the left pane click on Clear browsing data In the new window that opens go to Advanced tab Set Time Range to All Time -> check Cached Images and Files -> click on Clear data Restart your computer, It should start redirecting addresses mentioned in Hosts file (C:\Windows\System32\drivers\etc\hosts)

Note: This Solution is only for Google Chrome

2
  • 1
    I think the only thing missing from this list is, burn computer, buy a new computer. I'm pretty this is totally over the top
    – Liam
    Dec 6, 2022 at 16:27
  • Hey man, I am just here to help. If you have a better solution, you are welcome to post it. And I don't see whats the big deal with clearing cache, it's actually a good thing to keep clearing it every once in a while maybe 6 months or so.
    – Ghazali
    Dec 7, 2022 at 17:32
5

Try clearing the DNS Cache:

1) run cmd.exe as administrator

2) type: ipconfig /flushdns

2
  • Sorry, missed that one. I had already tried that too. I just tried again though, but no luck. I'll add that to my original post. Mar 7, 2017 at 13:57
  • On Ubuntu it seems like I had to run resolvectl flush-caches Feb 20 at 15:44
5

I just encountered this tonight and none of these options worked. I discovered that Chrome now hides "www" (https://www.howtogeek.com/435728/chrome-now-hides-www-and-https-in-addresses.-do-you-care/). Chrome was using my hosts file, but I had to add "www." to my hostname in my hosts file since that's what the browser is actually requesting, even if it doesn't show it.

5

Running Chrome 105 on Windows 11, nothing seemed to work until I added ::1 (i.e. ipv6) in addition to 127.0.0.1. For example:

127.0.0.1           local.foo.com
::1                 local.foo.com
2
  • This did it for me, where literally everything else failed. I'd tried clearing host cache (chrome://net-internals/#dns), flushing dns (cmd: ipconfig /flushdns), changing the top level domain, from the one I'd been using (.com) to .local. Nothing worked, until I just wrote in my C:\Windows\System32\Drivers\etc\hosts file "::1 mydomain.com", and that did the trick.
    – felipeheld
    Nov 23, 2022 at 15:55
  • This is the only solution which worked for me. Jul 27 at 14:50
1

While it was stated that no proxy is being used, I have had the same issue on OS X while using a proxy and the eventual solution was to add a proxy-exception for this domain.

What the OP could try is turn off async DNS via command-line switch as mentioned here in 2015:

Async DNS: Remove toggle from about:flags

Async DNS is fairly stable at the moment, so we don't really need the toggle in about:flags anymore. (Note that the --enable-async-dns and --disable-async-dns command-line flags will still work for now.)

This, however, seems to have no effect in my case, as chrome://net-internals/#dns still displays the internal DNS-client as enabled with no obvious way to turn it off.

0
1

A little late, but after hours i find a solution. It seems that Google Chrome sometimes has problems on recognize the name of the hosts defined en /etc/hosts.

I'm using linux and i'm behind a proxy.

Try adding at the end of the name server: .localhost

Example:

At: /etc/hosts:

127.0.0.1       myservername.localhost

On the virtual-hosts of your server configuration you'll need to rename the server name. In my case, i'm using apache so at /etc/apache/sites-enabled/myserver.conf rename the line of the old server name with:

...
ServerName:  myservername.localhost

If you are behind a proxy, you can except all the hosts just adding to the no_proxy vars:

$no_proxy= "localhost"

Finally don't forget to restart the server and try to access on the browser with the new server name.

1

😊 simple answer 😊
there are 3 workarounds about this:
1- deleting Visited Links binary file (beauty👍)
2- using .local or .app instead of your desired TLD (standard & preferred by chrome docs but i don't like it)
3- restarting your computer (ugly👎)

deleting Visited Links binary:

  1. kill all chrome tasks (close all chrome windows:))
  2. delete C:\Users\[USERNAME]\AppData\Local\Google\Chrome\User Data\Default\Visited Links binary

you can define a function in your shell profile to perform this fast and just by a command whenever you face this issue: e.g:

function respectHosts () {
    $path = $HOME + "\AppData\Local\Google\Chrome\User Data\Default\Visited Links";
    Remove-Item $path;
}

important Note:

it is suggested that first time after deleting Visited Links binary file, also delete your history cause if you use a url from history, actually you are using the cached dns of that url too:

enter image description here

1

The answer from @tim-schmidt is the only thing that worked for me. The site was working on both wsl and windows command-line (curl) but not in chrome.

Adding both IPv4 and IPv6 domains in hosts file solved it.

::1 www.mysite.local
127.0.0.1 www.mysite.local

Current setup: Windows 11 + WSL2 Ubuntu + Google Chrome

What didn't work for me:

  • dns flush in windows
  • reboot
  • adding only one between IPv4 or IPv6
  • disabling chrome Async DNS flag (chrome://flags/#enable-async-dns)
  • disabling chrome secure DNS security option (chrome://settings/security)
0

Had a similar issue working from a windows based server that had proxy settings. In the proxy advanced settings there are 2 options that can help. Ignore proxy setting for local hosts which is a check box; as well as a list of addresses set off my semi-colons where you can except out certain IP destinations. This fixed my issue.

0

For me

chrome://net-internals/#sockets

Flush socket pools work wonder, credit: https://superuser.com/a/611712

0

Chrome recognizes the URLs mapped to IP ::1 and you must also specify the subdomain example www.

Example: You need to insert the following line for blocking www.youtube.com:

::1      www.youtube.com

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.