Contents

Chrome 反向導向 DNS 網址

最近要找有沒有簡單可以在電腦測試特定網域網站連到指定主機,有想過改在 hosts 檔案,但又不想影響電腦程式連線功能,有看到 Chrome 裝套件可以達成目的,但我發現有比較好的方法,透過指令參數就可以達成這個問題。

套件方法

https://github.com/Riant/chrome-simply-proxy

Riant/chrome-simply-proxy: Chrome 的简易代理插件

有看到有人說替換網域用 proxy 作法會比較好

Chrome 指令參數調整(推薦)

注意,使用時要先把 Chrome 關掉,這樣才不會影響。還需要注意導向網站需要活者,沒有活著的話會是倒到真正網頁,所以需要特別注意。

1
2
3
4
5
6
7
# 任意網域調整 127.0.0.1
chrome.exe --host-resolver-rules="MAP * 127.0.0.1:5000" --no-proxy-server


chrome.exe --host-resolver-rules="MAP * 127.0.0.1" --no-proxy-server

chrome.exe --host-resolver-rules="MAP httpbin.org 127.0.0.1" --no-proxy-server

Simulate manipulation of the etc/hosts file in Google Chrome - Super User

CURL 也可以這樣用

參考:Chrome 指定域名解析,绕过 hosts - Est’s Blog

參數:

-4, –ipv4
-6, –ipv6
–dns-interface <interface>
–dns-ipv4-addr <ip-address> Tell curl to bind to <ip-address> when making IPv4 DNS requests
–dns-ipv6-addr <ip-address> Tell curl to bind to <ip-address> when making IPv6 DNS requests
–dns-servers <ip-address,ip-address> Set the list of DNS servers to be used instead of the system default. The list of IP addresses should be separated with commas. Port numbers may also optionally be given as :<port-number> after each IP address.
–resolve <host:port:address> Make the curl requests(s) use a specified address and prevent the otherwise normally resolved address to be used. Consider it a sort of /etc/hosts alternative provided on the command line. The port number should be the number used for the specific protocol the host will be used for. It means you need several entries if you want to provide address for the same host but different ports. This option can be used many times to add many host names to resolve. (Added in 7.21.3)

最後一個很有用 😹

1
 curl   http://www.example.com --resolve www.example.com:80:127.0.0.1

參考: Use cURL’s “–resolve” option to pin a request to an IP address

另類方法

Switch firefox to use a different DNS than what is in the windows.host file - Stack Overflow

剛剛看 Firefox 設定可以設定 DNS Over Https ,在想可以設定相關 Server,自己瀏覽器設定相關設定,也不會影響所以有電腦,不過感覺還是有點麻煩,所以就先不研究。

Fiddler

需要安裝Fiddler | Web Debugging Proxy and Troubleshooting Solutions,但是這也是很麻煩一件事。

彩蛋