Skip to content

Commit

Permalink
Set search domain for systemd-resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Mar 26, 2023
1 parent 980d4bf commit 8848c0e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tun_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net"
"net/netip"
"os"
"os/exec"
"runtime"
"syscall"
"unsafe"
Expand All @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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()
}

0 comments on commit 8848c0e

Please sign in to comment.