From 70b152fe77af93ea3e0b6244a586182016d568e2 Mon Sep 17 00:00:00 2001 From: Nikan Zeyaei <72458440+NikanZeyaei@users.noreply.github.com> Date: Mon, 23 Nov 2026 23:34:11 +0330 Subject: [PATCH] fix(sub): enable remote DNS resolution in Clash WireGuard proxies (#7154) Mihomo ignores a WireGuard proxy's dns list unless remote-dns-resolve is set, so destination domains were resolved by the client's local DNS outside the tunnel and timed out on poisoned networks. The flag is emitted only when every configured server is a bare IP: mihomo aborts the whole config on a value its name-server parser rejects. That is the rule the AmneziaWG builder already applies. Closes #7151 --- internal/sub/clash_service.go | 5 ++++ internal/sub/clash_service_test.go | 46 ++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/internal/sub/clash_service.go b/internal/sub/clash_service.go index 198b66001..e0fb3ae8c 100644 --- a/internal/sub/clash_service.go +++ b/internal/sub/clash_service.go @@ -701,6 +701,11 @@ func (s *SubClashService) buildWireguardProxy(subReq *SubService, inbound *model } if len(servers) > 0 { proxy["dns"] = servers + // mihomo ignores dns without this flag, but aborts the whole config on + // a value its dns.ParseNameServer rejects, so only bare IPs opt in. + if allBareIPs(servers) { + proxy["remote-dns-resolve"] = true + } } } diff --git a/internal/sub/clash_service_test.go b/internal/sub/clash_service_test.go index 0afe2e7bb..ca9430c4a 100644 --- a/internal/sub/clash_service_test.go +++ b/internal/sub/clash_service_test.go @@ -1159,6 +1159,52 @@ func TestBuildWireguardProxyForClash(t *testing.T) { } } +func TestBuildWireguardProxyForClashRemoteDNSResolve(t *testing.T) { + clientPriv, _, err := wgutil.GenerateWireguardKeypair() + if err != nil { + t.Fatalf("client keypair: %v", err) + } + tests := []struct { + name string + dns string + wantDNS []string + wantRemote bool + }{ + {name: "bare ips opt in", dns: "1.1.1.1, 8.8.8.8", wantDNS: []string{"1.1.1.1", "8.8.8.8"}, wantRemote: true}, + {name: "doh url keeps dns without the flag", dns: "https://1.1.1.1/dns-query", wantDNS: []string{"https://1.1.1.1/dns-query"}}, + {name: "mixed list is not all bare", dns: "1.1.1.1, dns.example.com", wantDNS: []string{"1.1.1.1", "dns.example.com"}}, + {name: "no dns", dns: ""}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + svc := &SubClashService{SubService: &SubService{}} + inbound := &model.Inbound{ + Listen: "203.0.113.9", + Port: 51820, + Protocol: model.WireGuard, + Settings: `{"dns":"` + tt.dns + `"}`, + } + client := model.Client{Email: "user", PrivateKey: clientPriv, AllowedIPs: []string{"10.0.0.2/32"}} + + proxy := svc.buildProxy(svc.SubService, inbound, client, nil, nil) + if proxy == nil { + t.Fatal("buildProxy returned nil") + } + dns, _ := proxy["dns"].([]string) + if !reflect.DeepEqual(dns, tt.wantDNS) { + t.Fatalf("dns = %v, want %v", proxy["dns"], tt.wantDNS) + } + remote, present := proxy["remote-dns-resolve"] + if tt.wantRemote && remote != true { + t.Fatalf("remote-dns-resolve = %v, want true", remote) + } + if !tt.wantRemote && present { + t.Fatalf("remote-dns-resolve = %v, want absent", remote) + } + }) + } +} + func TestBuildWireguardProxyForClashNoKey(t *testing.T) { svc := &SubClashService{SubService: &SubService{}} inbound := &model.Inbound{Listen: "203.0.113.9", Port: 51820, Protocol: model.WireGuard, Settings: `{}`}