Chrome 指定域名解析,绕过 hosts

看到 V站有人问这个,随手一记

可以参考源码里的注释文档

--host-resolver-rules=rules

Like --host-rules but these rules only apply to the host resolver.
A comma-separated list of rules that control how hostnames are mapped.
For example:
- MAP * 127.0.0.1 Forces all hostnames to be mapped to 127.0.0.1
- MAP *.google.com proxy Forces all google.com subdomains to be resolved to proxy.
- MAP test.com [::1]:77 Forces test.com to resolve to IPv6 loopback. Will also force the port of the resulting socket address to be 77.
- MAP * baz, EXCLUDE www.google.com Remaps everything to baz, except for www.google.com.

These mappings apply to the endpoint host in a net request (the TCP connect and host resolver in a direct connection, and the CONNECT in an HTTP proxy connection, and the endpoint host in a SOCKS proxy connection).

官方文档有语焉不详的提到过

https://chromium.googlesource.com/chromium/src/+/refs/heads/main/net/dns/README.md

Starting Chrome with --host-resolver-rules="MAP the.hostname.com [dead::beef]" where the.hostname.com is the hostname to allow resolving and dead::beef is the IPv6 address to resolve it to. net::MappedHostResolver acts at a level before IPv6 connectivity checks, and if a hostname is remapped to an IP literal, connectivity checks do not apply.

还有很多 proxy的参数

curl 的参数

也顺便贴一下。调试的时候用得上

参数:

最后一个很有用 😹

Comments