From 4f064aba6aa9eb8d9efd0d3c878d4c4fb8e2a043 Mon Sep 17 00:00:00 2001 From: Zxneric <87642935+Zxneric@users.noreply.github.com> Date: Wed, 13 Nov 2024 16:01:10 +0000 Subject: [PATCH] remove dns if no address was set --- tun_windows.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tun_windows.go b/tun_windows.go index 392b78c..294bc3a 100644 --- a/tun_windows.go +++ b/tun_windows.go @@ -84,6 +84,12 @@ func (t *NativeTun) configure() error { } } } + } else { + // If no IPv4 address is set, remove any existing IPv4 DNS servers + err := luid.SetDNS(winipcfg.AddressFamily(windows.AF_INET), nil, nil) + if err != nil { + return E.Cause(err, "remove ipv4 dns") + } } if len(t.options.Inet6Address) > 0 { err := luid.SetIPAddressesForFamily(winipcfg.AddressFamily(windows.AF_INET6), t.options.Inet6Address) @@ -102,6 +108,12 @@ func (t *NativeTun) configure() error { } } } + } else { + // If no IPv6 address is set, remove any existing IPv6 DNS servers + err := luid.SetDNS(winipcfg.AddressFamily(windows.AF_INET6), nil, nil) + if err != nil { + return E.Cause(err, "remove ipv6 dns") + } } if len(t.options.Inet4Address) > 0 || len(t.options.Inet6Address) > 0 { _ = luid.DisableDNSRegistration()