Google Chrome Ignoring Hosts File
Asked Answered
S

15

77

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?

Sociable answered 6/3, 2017 at 22:22 Comment(5)
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.Kilk
This just happened to me working with a client. I tested with Firefox and it worked immediately.Cooe
I have same problem on oracle linux using a proxy on Version 63.0.3239.132 (Official Build) (64-bit)Quitrent
What is the name of the domain you're trying to access?Overskirt
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.Mcelrath
S
41

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.

Sunglass answered 11/8, 2018 at 16:22 Comment(5)
Include .app too!Munguia
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.Sociable
I use .local but Chrome still ignores the hosts file.Thistledown
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.Sterigma
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?Polard
S
31

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

Stratus answered 11/10, 2021 at 20:49 Comment(5)
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.Vergne
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?Cynde
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.Disparage
I had to restart Chrome after changing this.Cassondra
Oh god how did I not find this answer earlier.... Only after this it works nowBlinker
B
17

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

Bioluminescence answered 16/1, 2019 at 18:43 Comment(5)
I'm on linux and the solution in google groups worked for me. Thanks!Chappell
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.Ammonic
@Ammonic 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.Bioluminescence
@karl-wilbur Apologies, I make no judgement on Linux, I'm purely talking about Windows 10.Ammonic
Hi guys, it started happening on Windows 10 for me this week. :(Uniocular
L
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

Louanneloucks answered 21/8, 2018 at 18:4 Comment(2)
I think the only thing missing from this list is, burn computer, buy a new computer. I'm pretty this is totally over the topWeasner
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.Louanneloucks
R
9

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
Rinker answered 14/9, 2022 at 17:3 Comment(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.Aldebaran
This is the only solution which worked for me.Palma
C
6

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.

Clamber answered 10/12, 2020 at 1:55 Comment(0)
P
4

Try clearing the DNS Cache:

1) run cmd.exe as administrator

2) type: ipconfig /flushdns

Paganize answered 6/3, 2017 at 22:41 Comment(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.Sociable
On Ubuntu it seems like I had to run resolvectl flush-cachesNamangan
Y
2

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.

Yaelyager answered 6/9, 2019 at 12:0 Comment(0)
N
2

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)
Nuptial answered 20/6, 2023 at 14:56 Comment(0)
A
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.

Afra answered 13/11, 2017 at 14:52 Comment(0)
C
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

Carburetor answered 24/11, 2021 at 10:57 Comment(0)
M
1

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
Mafalda answered 17/8, 2023 at 5:19 Comment(0)
K
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.

Kissel answered 17/11, 2021 at 19:12 Comment(0)
S
0

For me

chrome://net-internals/#sockets

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

Spondylitis answered 8/2, 2023 at 1:51 Comment(0)
B
0

You could bypass the host file issue altogether by running this command:

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --guest --host-resolver-rules="MAP example.com 1.2.3.4" --ignore-certificate-errors "example.com"

Note: all other instances of Chrome must be stopped for this to work.

It opens a new Chrome instance, with a domain mapped to an IP, and navigates to that domain.

Billi answered 11/4 at 18:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.