Shit! 我的host到底怎么了?

本文涉及的产品
云解析 DNS,旗舰版 1个月
全局流量管理 GTM,标准版 1个月
公共DNS(含HTTPDNS解析),每月1000万次HTTP解析
简介: 背景 那是今年五月的某一天,我的mac在切换系统host后,chrome迟迟不生效,依然访问的是原来的环境. 开发和测试同学在做项目时,需要经常进行 日常环境 预发环境 线上环境的切换,其实切的就是系统的host.如果浏览器总是延迟,或者死活不生效的活,基本上你就在那不停的刷新\刷新\刷新. 或者重新启动浏览器.心情会很烦躁的有木有. 解决方案 遇到这个问题的时候,一般我们有以

背景

那是今年五月的某一天,我的mac在切换系统host后,chrome迟迟不生效,依然访问的是原来的环境.
开发和测试同学在做项目时,需要经常进行 日常环境 预发环境 线上环境的切换,其实切的就是系统的host.如果浏览器总是延迟,或者死活不生效的活,基本上你就在那不停的刷新刷新刷新. 或者重新启动浏览器.心情会很烦躁的有木有.

解决方案

遇到这个问题的时候,一般我们有以下几个搞法(只针对chrome哈,重启浏览器就不说了,我标签一般打开好几十,轻易不愿意重启的)

第0招: 强清缓存思路. ctrl + shift + r 或者 刷新按钮 右键弹出一下菜单.

image.png
正常重新加载 Ctrl+R:正常重新加载。 

硬性重新加载:Ctrl+Shift+R:浅层次的清除历史记录,但不一定缓存完全清除。(Ctrl+F5)同理。 
清空缓存并硬性重新加载:可以深层次的清除所有的缓存。(建议用这个)

但其实这种做法对切换host没实际作用!

第一招: 打开 chrome://net-internals/#dns 页面, 点击 Clear host cache. 一般来讲, 有些同学使用这招可以解决host切换的不生效问题了.但是我的chrome使用此招还是无果.

image.png

Click on the button to Clear the host resolver cache entries. You would find that the entries in the list would be immediately cleared.By clearing the host resolver cache, you can force Google Chrome to resolve the domains again.

第二招: 打开 chrome://net-internals/#sockets 页面, 点击 Flush socket pools. 这招非常狠.终极杀手!绝对解决问题.

image.png

终极工具

零: 打开 https://zoom.alibaba-inc.com/ 安装ZOOM插件.

一. 在页面右键菜单上会发现[彻底清host缓存]的工具, 当然我还做了放置http强制跳转https

image.png

二. 点击[彻底清host缓存]菜单,弹出提示,让你去开启一个权限. 点击[前往设置]哈.开启权限后,浏览器会重启以启用新的配置.

image.png

三. 浏览器重启后,以后需要清dns,右键点击[彻底清host缓存]后,就ok了.成功后,会给你一个提示

image.png

这个提示里面,有个贴心的小功能,发现没.

涨点姿势

DNS缓存
感觉下面这段英语描述其实很简单易懂的,所以我就不放中文了.
A DNS cache (sometimes called a DNS resolver cache) is a temporary database, maintained by a computer's operating system, that contains records of all the recent visits and attempted visits to websites and other internet domains.

In other words, a DNS cache is just a memory of recent DNS lookups that your computer can quickly refer to when it's trying to figure out how to load a website.

Most people only hear the phrase "DNS cache" when it refers to flushing/clearing the DNS cache in order to help fix an internet connectivity issue. There's more on that at the bottom of this page.

为什么要设置DNS 本地缓存?
domain --> [DNS server] --> IP

Even though there are tons of public DNS servers your network can use to try to speed up the conversion/resolution process, it's still quicker to have a local copy of the map list, which is where DNS caches come into play.

How a DNS Cache Works
Before a browser issues its requests to the outside network, the computer intercepts each one and looks up the domain name in the DNS cache database. The database contains a list of all recently accessed domain names and the addresses that DNS calculated for them the first time a request was made.

Chrome 监听host变动
Note that Chrome now monitors the hosts file and autoclears the dnscache whenever there are any changes to the hosts file. —You can easily test if that works on your system by adding a blank line after your hosts file, and the list at chrome://net-internals/#dns will be autoupdated.— Windows' dnscache service will also (at least on win 8.1) monitor the hosts file for changes, so after you have updated your hosts file, simply clicking on the button "Flush socket pools" will work. Nothing else is needed. 

仅仅清DNS Cache为何还不足够?
Chrome使用DNS cache和Socket Pool来加速访问.其实Chrome的DNS cache会在切换hosts文件之后会自动清理,但是Socket Pool不会.(Chrome can't use the correct hosts after modifying the hosts file because of Chrome using socket pools.)

Chrome maintains long connections in the connection pool to speed up. When Chrome finds that a request can reuse a connection in the connection pool, it won't go through the DNS again, thus, we always perceive that Chrome won't respond to a hosts change immediately.

为什么我要做这个插件
Chrome has provided an interface for flushing the connection pool in the chrome://net-internals/#sockets tab, but I think it's annoying that I have to go to the tab first, and click so a small button with a trackpad.

I found that when clicking the button of flush socket pool, Chrome executes two key JavaScript methods.

g_browser.sendFlushSocketPools();
g_browser.checkForUpdatedInfo(false);

在chrome://* 页面下,可以发现 window下有个g_browser的对象,其中包含了很多方法.

image.png

根据这些搜索chrome的源码,找到了源头: https://searchcode.com/codesearch/view/86220162/. g_browser 的一堆方法都在这个BrowserBridge类里面.

image.png
image.png

每次都打开chrome://net-internals/#sockets页面去点击flush按钮是很烦的.于是我在想, 通过chrome插件自动打开这个页面,然后自动执行 g_browser.sendFlushSocketPools() 岂不是很完美?!

qutos

相关文章
|
11月前
|
应用服务中间件 nginx
HOST 碰撞
HOST 碰撞
64 0
|
1天前
|
安全 关系型数据库 MySQL
bah-host碰撞-pspy+sheallinabox
bah-host碰撞-pspy+sheallinabox
6 1
|
3月前
|
应用服务中间件 nginx Docker
connect() failed (113: No route to host) while connecting to upstream
connect() failed (113: No route to host) while connecting to upstream
101 0
|
4月前
|
网络安全
阿里云Could not connect to SITP host: smtp.163.com,port: 25;
阿里云Could not connect to SITP host: smtp.163.com,port: 25;
133 1
|
12月前
|
Linux 网络安全
ssh: connect to host 10.13.69.163 port 22: No route to host
ssh: connect to host 10.13.69.163 port 22: No route to host
|
12月前
|
Kubernetes 网络协议 容器
kubectl命令报错:Unable to connect to the server: dial tcp XXX:16443: connect: no route to host
kubectl命令报错:Unable to connect to the server: dial tcp XXX:16443: connect: no route to host
859 0
The connection to the server ip:6443 was refused - did you specify the right host or port
The connection to the server ip:6443 was refused - did you specify the right host or port
|
分布式计算 Hadoop 网络安全
三十一、 master: ssh: connect to host master port 22: No route to host
三十一、 master: ssh: connect to host master port 22: No route to host
三十一、 master: ssh: connect to host master port 22: No route to host
获取application server 主机名(host name)和端口号(port)的FM TH_GET_VIRT_HOST_DATA
获取application server 主机名(host name)和端口号(port)的FM TH_GET_VIRT_HOST_DATA
580 0
获取application server 主机名(host name)和端口号(port)的FM TH_GET_VIRT_HOST_DATA