Chrome now treating IP address of localhost same as somesite.localhost
Asked Answered
C

1

4

For a while I have been running two different server environments on my Windows 7 OS. IIS runs on 127.0.0.1 and I have a Vagrant VM that uses 192.168.33.10. My hosts file looks something like:

  • vagrantsite1.localhost 192.168.33.10
  • vagrantsite2.localhost 192.168.33.10
  • iissite1.localhost 127.0.0.1
  • iissite2.localhost 127.0.0.1

Up until a week or so back, this setup worked perfectly fine, however something has changed recently with my Chrome browser. Now all of a sudden in Chrome when I access vagrantsite1.localhost it is referencing the IIS 127.0.0.1 IP address instead of 192.168.33.10. I checked this using chrome://net-internals/#dns and even cleared the host cache, which did not seem to resolve anything.

After some research I have found if I add localhost 192.168.33.10 to my hosts file, the vagrant sites work, however now my IIS sites try to access this IP instead of 127.0.0.1. It seems that Chrome does not let me use a different IP for somesite.localhost from localhost entry. This is not a problem in IE and Firefox, and up until recently it was not a problem in Chrome.

I was wondering if anyone else has this problem or a potential solution (rather than manually setting localhost IP each time I want to switch servers)? I realize I can use a different port number for one of the servers as a solution, however since everything works fine in IE and Firefox, and until recently worked fine in Chrome, I would like to know the cause.

Coot answered 1/6, 2015 at 17:37 Comment(2)
What IP shows when you ping vagrantsite1.localhost? If it show 127.0.0.1 it might be a mis-configurationVagarious
When I ping vagrantsite1.localhost I get 192.168.33.10. When I look in Chrome at chrome://net-internals/#dns after I clear host cache and visit vagrantsite1.localhost, I see new entry for localhost 127.0.0.1. It's as if Chrome is getting confused thinking that vagrantsite1.localhost = localhost, which is not the case. As mentioned this only happens in Chrome, Firefox and IE appear to be resolving the correct IP.Coot
S
5

This is a "feature" that was just added to chrome, all localhost domains will always resolve to loopback.

See the following links for more information:

One workaround is to change your entries to not end in localhost, something like "vagrantsite1.local 192.168.33.10" instead should work.

Superscribe answered 4/6, 2015 at 13:44 Comment(2)
Thank you, this is frustrating when new "features" like this get introduced and end up causing havoc. I prefer to use the .localhost extension but will switch to local for now.Coot
Just had this exact moment of realisation! Thanks for confirming my suspicions. A dev server called client.localhost had stopped working. Various different errors shown but all because they were being resolved to the dev's own machines (in Chrome).Coston

© 2022 - 2024 — McMap. All rights reserved.