Chrome Slow to Resolve /etc/hosts on macOS – Fix DNS Issues

dnsgoogle-chromehosts-filemacnetworking

Our developers use either Docker or VirtualBox (with Vagrant) to test their code locally (and the problem happens with both). To facilitate this, we modify /etc/hosts to point to the correct IP address. For example,

local.test.company.com 10.200.10.1

Some of our developers are on Linux and some are on macOS Sierra (10.12.3). On Mac, requests to local.test.company.com in Chrome (and other browsers) often take a long time (up to a minute or more) to resolve. (The problem doesn't happen on Ubuntu Linux.) During this time, the "loading icon" on the tab is the gray icon spinning to the left. As soon as it changes to the blue icon spinning to the right, it finishes very quickly. The slow loading time can be a real problem for our developers who often refresh the site during development.

Based on this question, it seems that Chrome is taking a full minute to resolve the site. This doesn't make sense to me – a site in /etc/hosts should resolve immediately. Some developers can reproduce this behavior very consistently. Others see it intermittently or don't see it at all, and I have not been able to figure out why.

Why do the requests to local.test.company.com take a long time to resolve in a web browser?

Or, what can I do to "debug" this problem and figure out what's taking so long?


Additional Notes

  • The behavior continues to happen with Chrome in "incognito mode" with "disable cache" turned on.
  • ping resolves local.test.company.com immediately.

Best Answer

I had the same issue in Chrome 64.0.3282.167 on macOS High Sierra (10.13.3) and this StackOverflow answer solved it for me:

https://stackoverflow.com/a/10200111/318359

Quote:

Put all your hosts file entries for localhost into one line like so:

127.0.0.1 localhost myproject.dev myotherproject.dev 
::1 localhost
Related Question