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() +}