clash dns配置,如何让使用DIRECT的域名走真实ip,需要代理的域名走fake-ip。我使...

Criado em: 27 de dezembro de 2025

Respondido usando GPT-5.2 Thinking por Chat01

Pergunta

clash dns配置,如何让使用DIRECT的域名走真实ip,需要代理的域名走fake-ip。我使用TUN模式

Pensamento

Providing guidance for TUN proxy configuration

In TUN mode, set dns.enhanced-mode: fake-ip and use dns.fake-ip-filter to exclude direct domains from fake IP mapping. Mihomo supports using wildcards and importing domain sets like rule-set and geosite. For classic Clash, manually list domains, as geosite/rule-set support isn't available.

Configuring TUN with DNS hijacking for optimal results

To optimize TUN, enable dns-hijack to redirect all query traffic to internal DNS. Set dns.listen and possibly 127.0.0.1:1053. Use dns-hijack any:53 for best results. A sample configuration includes internal DNS, fake IP settings, and domain filtering for direct and local domains.

Clarifying DNS and proxy behavior with respect-rules

DNS servers can differ, so examples should be adjusted. The respect-rules setting impacts how DNS queries connect, not the answer type. The answer type is controlled by fake-ip-filter. If using it to bypass, domains get real IPs, so don’t rely on fake IP mapping for routing. Avoid proxy domains in the filter.

Verifying direct domain setup and rule-set for GEOIP

They asked for a direct domain list, but might prefer using GEOIP for IP lists instead. If they want direct domains, we should show an example with rule-set for domains like rule-set:cn, using entries from DNS docs. We’ll cite the appropriate parts where fake-ip-filter includes “rule-set:xxx” and “geosite:xxx”.

Thought for 1m 19s

Resposta

TUN + fake-ip 场景里,Clash(更准确说是 mihomo / Clash.Meta 内核)要实现:

  • 走 DIRECT 的域名 → 返回真实 IP
  • 需要代理的域名 → 返回 fake-ip

核心就一条:dns.fake-ip-filter 把“DIRECT 域名集合”排除出 fake-ip 映射(或反过来用 whitelist 只给“代理域名集合”发 fake-ip)。mihomo 的 fake-ip-filter 支持直接引用 rule-set / geosite,不用手写一堆域名。 (Metacubex Wiki)


方案 A(更常用):blacklist 排除 DIRECT → DIRECT 走真实 IP,其他走 fake-ip

fake-ip-filter-mode: blacklist 表示:命中 filter 的域名不返回 fake-ip(返回真实解析)。 (Metacubex Wiki)

yaml
tun: enable: true stack: system auto-route: true auto-detect-interface: true dns-hijack: - any:53 - tcp://any:53 dns: enable: true listen: 0.0.0.0:1053 enhanced-mode: fake-ip fake-ip-range: 198.18.0.1/16 fake-ip-filter-mode: blacklist fake-ip-filter: - "rule-set:direct" # ✅ 你的 DIRECT 域名集合:返回真实 IP - "+.lan" - "+.local" # 下面是解析策略示例(按需改你自己的 DNS) default-nameserver: [223.5.5.5] nameserver: [https://dns.alidns.com/dns-query, https://doh.pub/dns-query] fallback: [tls://1.1.1.1, tls://8.8.4.4] fallback-filter: geoip: true geoip-code: CN geosite: [gfw]
  • dns-hijack 用来把系统/应用发往 53 端口的 DNS 导进 mihomo 内置 DNS(不然你配了 fake-ip 也可能没生效)。(Metacubex Wiki)
  • fake-ip-filter 支持直接写 rule-set:xxx / geosite:xxx。(Metacubex Wiki)

你的规则里同时要有对应的路由规则,例如:

yaml
rules: - RULE-SET,direct,DIRECT - RULE-SET,proxy,PROXY - MATCH,PROXY

方案 B:whitelist 只让“需要代理的域名”拿 fake-ip(其余都是真实 IP)

如果“需要代理”的域名集合更小(比如 gfwlist),用 whitelist 维护更省事:

  • fake-ip-filter-mode: whitelist只有命中 filter 的域名才返回 fake-ip。(Metacubex Wiki)
yaml
dns: enhanced-mode: fake-ip fake-ip-filter-mode: whitelist fake-ip-filter: - "rule-set:proxy" # ✅ 需要代理的域名:返回 fake-ip - "+.lan" - "+.local"

常见坑提醒(跟你这个需求强相关)

  • 别指望“自动根据最终规则 DIRECT/PROXY”动态决定真 IP/fake-ip:实际是你用 fake-ip-filter(黑名单/白名单)决定返回类型;想自动化,最稳就是把你的 DIRECT/PROXY 域名整理成 rule-set,DNS 和 rules 同源引用。(Metacubex Wiki)
  • respect-rules 解决的是“DNS 请求走不走代理/走哪条出站”的问题,不是“返回真 IP 还是 fake-ip”。它需要配 proxy-server-nameserver。(Metacubex Wiki)

如果你告诉我你用的是哪个内核/客户端(Clash Verge Rev / Clash for Windows / Mihomo Party / OpenClash 等)以及你现在 DIRECT/PROXY 用的是什么规则集名字(比如 cndirectgfw),我可以把上面示例改成完全贴合你现有配置的片段。

Pergunta

Mihomo Party,是否可以根据最终规则动态决定返回?

Pensamento

Explaining dynamic fake-ip decision making

In Mihomo, whether a DNS response returns a fake or real IP is determined by the "enhanced-mode" and “fake-ip-filter/mode.” There's no mechanism to dynamically consult routing rules for this decision. Using "dns.respect-rules" helps with how DNS connections are established, but not with choosing the IP. To approximate dynamic behavior, domain sets for direct or proxy should be maintained and integrated into the fake-ip-filter.

Configuring fake IP behavior in Mihomo Party

Both fake-ip-filter and nameserver-policy can import domain sets, including rule-set:xxx. This allows updates via remote lists, though decisions are still made at query time. For Mihomo Party, use a blacklist in fake-ip-filter for "direct -> real IP" and whitelist for "proxy -> fake IP." Be cautious with apps requiring real IP (e.g., IP-literal). If more dynamic behavior is needed, try "enhanced-mode redir-host" with sniffing, but note that sniffing may not work well with QUIC or IP-only traffic.

Thought for 39s

Resposta

Mihomo Party(mihomo 内核)+ TUN + enhanced-mode: fake-ip 下,不能做到“按最终路由规则(DIRECT/PROXY)动态决定 DNS 返回真实 IP 还是 fake-ip”

原因很简单:fake-ip 的本质就是 DNS 阶段先把域名映射成 fake IP,后续连接打到这个 fake IP 时,内核才能“反查回域名”去做域名规则匹配(这是 fake-ip 机制用来支持域名分流的核心流程)。(DeepWiki)
所以“最终规则”本身往往依赖这个映射结果,DNS 阶段再去问“最终规则是什么”会变成鸡生蛋问题——mihomo 也没提供这种联动开关。

另外你提到的 dns.respect-rules(或 DNS 服务器地址里的 #RULES只影响“DNS 这条连接走不走代理/遵不遵守路由规则”,并不改变“返回 fake-ip 还是真实 IP”。(Metacubex Wiki)


能达到你想要效果的正确姿势(近似“动态”)

结论:dns.fake-ip-filter + 引用同一份 rule-set(让 DNS 和路由规则共享同一个域名集合)。mihomo 支持在 fake-ip-filter 里直接 rule-set:xxx 导入域名集。(Metacubex Wiki)

方案 1:DIRECT 域名返回真实 IP(推荐)

yaml
dns: enhanced-mode: fake-ip fake-ip-filter-mode: blacklist fake-ip-filter: - "rule-set:direct" # 命中 direct 的域名 -> 不给 fake-ip -> 返回真实 IP

fake-ip-filter 的语义就是:这些域名不进行 fake-ip 映射(直接返回真实解析)。(Metacubex Wiki)

方案 2:只有需要代理的域名才返回 fake-ip

yaml
dns: enhanced-mode: fake-ip fake-ip-filter-mode: whitelist fake-ip-filter: - "rule-set:proxy" # 只有命中 proxy 的域名 -> 才返回 fake-ip

whitelist 模式下:只有匹配到 filter 的域名才会返回 fake-ip。(Metacubex Wiki)

这两种都不是“按最终规则实时计算”,但如果你的 rule-set:direct / rule-set:proxy 来自 rule-providers 自动更新,那么实际使用体验就是“跟着规则集变化自动变化”。


如果你真的想“完全不维护域名集合”

只有一个方向:改成 enhanced-mode: redir-host(让 DNS 永远返回真实 IP),再靠 sniffer/SNI/HTTP Host 去还原域名分流;但这在 QUIC、某些应用、或没法嗅探的流量上不如 fake-ip 稳。(Metacubex Wiki)


如果你愿意贴一小段你现在的 rules:rule-providers:(把订阅/节点信息打码即可),我可以直接按你现有的 rule-set 名字,把 “DIRECT 走真实 IP、PROXY 走 fake-ip” 的最小可用配置片段给你拼好。

Pergunta

fake-ip 会影响网站获得到的我的IP吗

Pensamento

Clarifying fake-IP behavior with outbound IPs

Fake-IP doesn’t affect your outbound IP; for direct connections, the website sees your public IP; for proxy connections, it sees the proxy. WebRTC or STUN might still reveal your IP, and DNS leaks are possible. For websites, fake-IP won’t change your source IP, but proxy usage will. Some websites may detect a local IP via WebRTC, but this isn't due to fake-IP. Geolocation is based on the exit IP, so fake-IP affects what’s seen only locally.

Explaining fake-IP behavior for websites

Fake-IP won’t affect what websites see as your IP. For TUN mode, your app sends traffic to the fake-IP, but it's translated to the real destination, essentially working like local NAT. However, DNS over HTTPS could bypass this, making the DoH request leak. WebRTC leaks can reveal local or public IPs too, so it’s better to disable WebRTC if you're concerned. If you're using a direct connection, the website will definitely see your real public IP, but not if you’re using a proxy.

Thought for 20s

Resposta

不会。fake-ip 不会改变网站看到的“你的出口 IP”

网站能看到的 IP,本质是你和网站建立 TCP/UDP 连接时,数据包的源地址

  • 规则走 DIRECT:网站看到的是你家宽带/手机网络的公网 IP(运营商分配的那个)。
  • 规则走代理(PROXY):网站看到的是代理节点的出口 IP(节点所在机房的公网 IP)。

fake-ip 只是 DNS 阶段给域名返回一个“本地用的虚拟 IP”,用于 mihomo 在 TUN 场景里把“IP 连接”反查回“域名”,方便做域名分流;这个 fake IP 不会作为你的源地址发到公网,更不会变成“你对外的 IP”。(DeepWiki)

需要注意的“看起来像 IP 泄露”的情况(和 fake-ip 无关)

  • WebRTC/STUN 泄露:浏览器可能通过 WebRTC 探测到你的真实公网/内网 IP(取决于浏览器设置/扩展/策略)。这不是 fake-ip 导致的。
  • 你本来就走了 DIRECT:那网站当然能看到你的真实公网 IP —— 这就是 DIRECT 的定义。

如果你愿意贴一下你当前的 rules(尤其是浏览器/常用网站命中哪条规则),我可以帮你确认:哪些站点会看到真实公网 IP、哪些会看到节点出口 IP。

Compartilhar esta Q&A