環境:Windows 10、Chrome
效果:
不修改本機 C:\Windows\System32\drivers\etc\hosts 檔案,讓 chrome 也能解析自訂的網域規則
方法:
啟動 Chrome 時,加上 --host-resolver-rules 參數,該參數可以設定網域解析規則,只對當次開啟的 Chrome 有效,關閉後失效。
步驟:
- 先關閉所有 Chrome 視窗
- 用指令啟動 Chrome,並使用 --host-resolver-rules 參數,加上自訂的網域解析規則
- 方法1:Windows 鍵 + R
執行chrome.exe --host-resolver-rules="MAP test.example.com 127.0.0.1","MAP test2.example.com:9999 127.0.0.1:80","MAP *.example.org 127.0.0.1"
- 方法2:cmd 命令列
執行"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --host-resolver-rules="MAP test.example.com 127.0.0.1","MAP test2.example.com:9999 127.0.0.1:80","MAP *.example.org 127.0.0.1"
- 啟動參數檢視
chrome://version/ - 查看 Chrome 的網域 IP 解析結果
chrome://net-internals/#dns
後圖,加上 PORT 轉換的 test2.example.com:9999 雖然查不到,但後面語法解說測試,可正常運作 - --host-resolver-rules 參數的 MAP 語法
- "MAP test.example.com 127.0.0.1"
test.example.com 解析為 127.0.0.1 - "MAP test2.example.com:9999 127.0.0.1:80"
test2.example.com 解析為 127.0.0.1,並且 9999 PORT 導向 80 PORT - "MAP *.example.org 127.0.0.1"
所有 example.org 子網域都解析為 127.0.0.1 - "MAP * 127.0.0.1, EXCLUDE www.xyznote.cc"
除了 www.xyznote.cc,其他所有網域都解析為 127.0.0.1
後圖測試結果為執行"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --host-resolver-rules="MAP * 127.0.0.1, EXCLUDE www.xyznote.cc"
- 其他參數
- 以訪客身分瀏覽:使用 --guest 參數
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --guest --host-resolver-rules="MAP * 127.0.0.1, EXCLUDE www.xyznote.cc"
- 以無痕模式瀏覽:使用 --incognito 參數
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --incognito --host-resolver-rules="MAP * 127.0.0.1, EXCLUDE www.xyznote.cc"
參考:
- https://devopslife.io/resolve-dns-locally-using-google-chrome/
Resolve dns locally using google chrome · devopslife - https://superuser.com/questions/343158/simulate-manipulation-of-the-etc-hosts-file-in-google-chrome
Simulate manipulation of the etc/hosts file in Google Chrome - Super User - https://superuser.com/questions/1812598/in-google-chrome-what-does-host-resolver-rules-flag-do-when-used-with-proxy-serv
In Google Chrome what does host-resolver-rules flag do when used with proxy-server? - Super User - https://blog.est.im/2021/stdout-016
Chrome 指定域名解析,绕过 hosts – est の 输入 输出和出入 - https://stackoverflow.com/questions/14605636/host-rules-google-chrome-adding-configuration
command line - Host-rules google chrome, adding configuration - Stack Overflow - https://home.gamer.com.tw/creationDetail.php?sn=4568253
(算稍有解了──)⟪場外⟫【問題】 Google Chrome 管理使用者視窗,有參數? Note - aeGK0的創作 - 巴哈姆特













沒有留言:
張貼留言