From 960c3ce17b3cff88a75df43d8e805706ec16c3d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Thu, 12 Dec 2024 22:49:56 +0800 Subject: [PATCH] Fix set windows dns --- tun_windows.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tun_windows.go b/tun_windows.go index 85e3009..e69c0c4 100644 --- a/tun_windows.go +++ b/tun_windows.go @@ -72,7 +72,7 @@ func (t *NativeTun) configure() error { if err != nil { return E.Cause(err, "set ipv4 address") } - if !t.options.EXP_DisableDNSHijack { + if t.options.AutoRoute && !t.options.EXP_DisableDNSHijack { dnsServers := common.Filter(t.options.DNSServers, netip.Addr.Is4) if len(dnsServers) == 0 && HasNextAddress(t.options.Inet4Address[0], 1) { dnsServers = []netip.Addr{t.options.Inet4Address[0].Addr().Next()} @@ -83,6 +83,11 @@ func (t *NativeTun) configure() error { return E.Cause(err, "set ipv4 dns") } } + } else { + err = luid.SetDNS(winipcfg.AddressFamily(windows.AF_INET), nil, nil) + if err != nil { + return E.Cause(err, "set ipv4 dns") + } } } if len(t.options.Inet6Address) > 0 { @@ -90,7 +95,7 @@ func (t *NativeTun) configure() error { if err != nil { return E.Cause(err, "set ipv6 address") } - if !t.options.EXP_DisableDNSHijack { + if t.options.AutoRoute && !t.options.EXP_DisableDNSHijack { dnsServers := common.Filter(t.options.DNSServers, netip.Addr.Is6) if len(dnsServers) == 0 && HasNextAddress(t.options.Inet6Address[0], 1) { dnsServers = []netip.Addr{t.options.Inet6Address[0].Addr().Next()} @@ -101,6 +106,11 @@ func (t *NativeTun) configure() error { return E.Cause(err, "set ipv6 dns") } } + } else { + err = luid.SetDNS(winipcfg.AddressFamily(windows.AF_INET6), nil, nil) + if err != nil { + return E.Cause(err, "set ipv6 dns") + } } } if len(t.options.Inet4Address) > 0 || len(t.options.Inet6Address) > 0 {