From 8848c0e4cbab110d3d6b43c0a9dc2444307a9689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Sun, 26 Mar 2023 16:09:24 +0800 Subject: [PATCH] Set search domain for systemd-resolved --- tun_linux.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tun_linux.go b/tun_linux.go index 525dff3..e460aa8 100644 --- a/tun_linux.go +++ b/tun_linux.go @@ -5,6 +5,7 @@ import ( "net" "net/netip" "os" + "os/exec" "runtime" "syscall" "unsafe" @@ -13,6 +14,7 @@ import ( "github.com/sagernet/sing/common" E "github.com/sagernet/sing/common/exceptions" "github.com/sagernet/sing/common/rw" + "github.com/sagernet/sing/common/shell" "github.com/sagernet/sing/common/x/list" "golang.org/x/sys/unix" @@ -165,6 +167,8 @@ func (t *NativeTun) configure(tunLink netlink.Link) error { return err } + setSearchDomainForSystemdResolved(t.options.Name) + if t.options.AutoRoute && runtime.GOOS == "android" { t.interfaceCallback = t.options.InterfaceMonitor.RegisterCallback(t.routeUpdate) } @@ -594,3 +598,11 @@ func (t *NativeTun) routeUpdate(event int) error { } return nil } + +func setSearchDomainForSystemdResolved(interfaceName string) { + ctlPath, err := exec.LookPath("resolvectl") + if err != nil { + return + } + shell.Exec(ctlPath, "domain", interfaceName, "~.").Run() +}