Chrome 指定域名解析,绕过 hosts
Posted | stdout
看到 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 的参数
也顺便贴一下。调试的时候用得上
参数:
-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)
最后一个很有用 😹
Comments