Chrome 访问 hosts 映射到 127.0.0.1 的域名,DNS Lookup 的时间总是为 5秒

clipboard.png

如图,hello.me 映射到 127.0.0.1,刷新一下 Chrome(版本 55.0.x, macOS 10.12.2系统),DNS Lookup 的时间总是为 5 秒,不多不少,尝试了很多次。其他浏览器没有这个问题。

尝试换了不同关键词搜索到的但大都是不相关的问题。

/etc/resolv.conf 的文件内容:

clipboard.png


sorry,没表述清楚,我所说的映射到本地的域名意思就是指修改的 hosts。


附,通过 chrome://net-internals/#dns 查看 DNS 解析情况:

clipboard.png

看起来解析有一分钟的缓存,但实际上一刷新就已经过期了。


验证到最后,通过 nslookup 命令发现一个规律。。。只有 .me 后缀的域名受影响。。。

我决定换个域名。。。

阅读 12.6k
11 个回答

这个问题貌似一直没有下文了。。。
我最终发现的问题是:只有 .me 后缀的自定义映射到本地的域名会出现这种情况。

因为当时线上的网站用 .com/.cn/.net ,我就在本地用 .me 域名来指代。
也有部分本地开发的项目使用 .com 之类的后缀。

最终测试发现一个规律:
.me 都有这个问题,而 .com 都没有。

最终怀疑 Chrome 内部是不是对 .me 做了一些特别的事情。。。
我的理解是, HOST 应该是最高级别的 域名IP 映射。

下面的内容可以忽略了。。。

找到原因了。

clipboard.png

根据 Chrome 显示(使用命令),我开启了本地 DNS,并且是 No valid configuration found

https://productforums.google....;context-place=topicsearchin/chrome/Internal$20DNS$20client$20enabled

找到了一些信息,但貌似没有靠谱的解决方案。我决定先卸载 Chrome,重新安装一下。


重新安装没有用。


"Internal DNS client enabled" is a problem with VPN or local cache servers 这里有人说:

Example URL:
Any with multiple internal/external addresses

Steps to reproduce the problem:

  1. Configure VPN with DNSMasq or get a peplink with local DNS addresses.
  2. Access a site that has both internal/external address then disconnect/reconnect the VPN
  3. Depending on the site you'll get incorrectly routed or errors.

eg: if your internal minecraft server is connect to 192.168.4.10 but your peplink router won't let you connect via the external address from and internal address... you can configure the DNS proxy to 192.168.4.10 where the external is X.X.X.X problem is Google hits the 8.8.8.8 DNS and it's going to return X.X.X.X rather than 192.168.4.10.

I think I have a related issue.
I use DNSMasq to easily configure some local domains we use for development.
Those domains point to a couple of different virtual machines.
Usually it resolves fine when I start working, but at a random time (or at least that's how it feels :) ) it resolves to 127.0.0.1. As far as I know, I don't have that configured anywhere...
Clearing the DNS cache doesn't help, but restarting Chrome usually works for me (but is highly annoying with 20 tabs open).

对,我也安装过 DNSMasq。。。不过现在是关闭的。

不果仍然不能帮助我解决问题。。。


已尝试通过

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --flag-switches-begin --disable-async-dns --flag-switches-end 

命令来启动,还是无效

都让开~让我来!

关掉chrome相关插件,如:adblock这类广告屏蔽类插件,或其它作用于任何页面的插件

原因嘛:打开网页就会检查页面,而一些插件是国外写的,弄不好就会产生额外的不可描述的原因。
理论上打开本地localhost,是不会消耗什么时间成本的,更由于访问的是本地主机,怎么会产生这么长的DNS解析时长呢?
所以:最终的解决方法就是关掉chrome插件,不然你换个浏览器,如IE11访问试试会不会需要这么长时间

127.0.0.1 这种A记录也能做?
建议,要方向本地,可以直接使用127.0.0.1访问,或者直接修改hosts文件!

没能复现题主的情况

Chrome 55.0.2883.87 m (64-bit) on Windows 7

图片描述


补充:

我也看到了https://chromium.googlesource...

题主检查下这里看看:

图片描述

图片描述

观望者的路过 感觉不翻墙应该没事

遇到和楼主相同的问题,我本地是.dev的后缀,系统是OS X 10.12.6,浏览器是60.0.3112.90。

按照@郑凯文 的提示,关闭ADB后该问题消失。

感谢@郑凯文

遇到和楼主类似的问题,不过我在chrome、firefox、postman都会出现DNS Lookup占用时间长的问题,我本地配置的开发域名是.local的后缀,系统是macos 10.15,使用chrome浏览器。

解决方法:
不用关闭chrome的adb插件,直接更改本地开发域名后缀为'.local.com'后,就不再出现DNS Lookup占用时间过长的问题。

原理不知,大神知道的话就指点下哈。

我是检查到本地的hosts文件被docker修改过,注释掉就解决了image.png

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题