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
This commit is contained in:
Nikan Zeyaei
2026-11-23 23:34:11 +03:30
committed by GitHub
parent a2bc42c3a1
commit 70b152fe77
2 changed files with 51 additions and 0 deletions
+5
View File
@@ -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
}
}
}
+46
View File
@@ -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: `{}`}