mirror of
https://github.com/kubenetworks/kubevpn.git
synced 2025-12-24 11:51:13 +08:00
support linux dns resolve, short domain name resolve
This commit is contained in:
30
dns/dns_linux.go
Normal file
30
dns/dns_linux.go
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
// +build linux
|
||||||
|
|
||||||
|
package dns
|
||||||
|
|
||||||
|
import (
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
)
|
||||||
|
|
||||||
|
func DNS(ip string, namespace string) error {
|
||||||
|
tunName := os.Getenv("tunName")
|
||||||
|
if len(tunName) == 0 {
|
||||||
|
tunName = "tun0"
|
||||||
|
}
|
||||||
|
cmd := exec.Command("systemd-resolve", []string{
|
||||||
|
"--set-dns",
|
||||||
|
ip,
|
||||||
|
"--interface",
|
||||||
|
tunName,
|
||||||
|
"--set-domain=" + namespace + ".svc.cluster.local",
|
||||||
|
"--set-domain=svc.cluster.local",
|
||||||
|
}...)
|
||||||
|
output, err := cmd.CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
log.Warnf("cmd: %s, output: %s, error: %v\n", cmd.Args, string(output), err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// +build !windows
|
// +build darwin
|
||||||
|
|
||||||
package dns
|
package dns
|
||||||
|
|
||||||
|
|||||||
12
pkg/main.go
12
pkg/main.go
@@ -170,11 +170,7 @@ func main() {
|
|||||||
if err := start(); err != nil {
|
if err := start(); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
//time.Sleep(time.Second * 5)
|
|
||||||
dnsServiceIp := util.GetDNSServiceIpFromPod(clientset, restclient, config, util.TrafficManager, namespace)
|
|
||||||
if err := dns.DNS(dnsServiceIp, namespace); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
if !util.FindRule() {
|
if !util.FindRule() {
|
||||||
util.AddFirewallRule()
|
util.AddFirewallRule()
|
||||||
@@ -183,6 +179,12 @@ func main() {
|
|||||||
}
|
}
|
||||||
log.Info("dns service ok")
|
log.Info("dns service ok")
|
||||||
_ = exec.Command("ping", "-c", "4", "223.254.254.100").Run()
|
_ = exec.Command("ping", "-c", "4", "223.254.254.100").Run()
|
||||||
|
|
||||||
|
//time.Sleep(time.Second * 5)
|
||||||
|
dnsServiceIp := util.GetDNSServiceIpFromPod(clientset, restclient, config, util.TrafficManager, namespace)
|
||||||
|
if err := dns.DNS(dnsServiceIp, namespace); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
select {}
|
select {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user