mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-02-03 22:18:39 +00:00
cmd/ctrld: add --iface for setting DNS on specific interface
This commit is contained in:
committed by
Cuong Manh Le
parent
d5344aea52
commit
b00a7c34ee
35
internal/resolvconffile/dns.go
Normal file
35
internal/resolvconffile/dns.go
Normal file
@@ -0,0 +1,35 @@
|
||||
//go:build !js && !windows
|
||||
|
||||
package resolvconffile
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"tailscale.com/net/dns/resolvconffile"
|
||||
)
|
||||
|
||||
const resolvconfPath = "/etc/resolv.conf"
|
||||
|
||||
func NameServersWithPort() []string {
|
||||
c, err := resolvconffile.ParseFile(resolvconfPath)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
ns := make([]string, 0, len(c.Nameservers))
|
||||
for _, nameserver := range c.Nameservers {
|
||||
ns = append(ns, net.JoinHostPort(nameserver.String(), "53"))
|
||||
}
|
||||
return ns
|
||||
}
|
||||
|
||||
func NameServers(_ string) []string {
|
||||
c, err := resolvconffile.ParseFile(resolvconfPath)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
ns := make([]string, 0, len(c.Nameservers))
|
||||
for _, nameserver := range c.Nameservers {
|
||||
ns = append(ns, nameserver.String())
|
||||
}
|
||||
return ns
|
||||
}
|
||||
13
internal/resolvconffile/dns_test.go
Normal file
13
internal/resolvconffile/dns_test.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package resolvconffile
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestNameServers(t *testing.T) {
|
||||
ns := NameServers("")
|
||||
require.NotNil(t, ns)
|
||||
t.Log(ns)
|
||||
}
|
||||
Reference in New Issue
Block a user