From d7864f134ed3f3d746935b2ff0f84bab4bfe7268 Mon Sep 17 00:00:00 2001 From: eronez <55025357+eronez@users.noreply.github.com> Date: Wed, 11 Feb 2026 06:54:47 +0000 Subject: [PATCH] Add unsetSearchDomainForSystemdResolved Add `unsetSearchDomainForSystemdResolved` to revert dns setting before `unsetAddresses` while closing TUN. --- tun_linux.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tun_linux.go b/tun_linux.go index f35921e..ffaea20 100644 --- a/tun_linux.go +++ b/tun_linux.go @@ -325,6 +325,7 @@ func (t *NativeTun) Close() error { if t.options.EXP_ExternalConfiguration { return common.Close(common.PtrOrNil(t.tunFile)) } + t.unsetSearchDomainForSystemdResolved() t.unsetAddresses() return E.Errors(t.unsetRoute(), t.unsetRules(), common.Close(common.PtrOrNil(t.tunFile))) } @@ -1094,3 +1095,17 @@ func (t *NativeTun) setSearchDomainForSystemdResolved() { _ = shell.Exec(ctlPath, append([]string{"dns", t.options.Name}, common.Map(dnsServer, netip.Addr.String)...)...).Run() }() } + +func (t *NativeTun) unsetSearchDomainForSystemdResolved() { + if t.options.EXP_DisableDNSHijack { + return + } + ctlPath, err := exec.LookPath("resolvectl") + if err != nil { + return + } + _ = shell.Exec(ctlPath, "revert", t.options.Name).Run() + if t.options.Logger != nil { + t.options.Logger.Debug("cleaned up DNS configuration for interface: ", t.options.Name) + } +}