Browse Source

remove DNS from wireguard conf and revert to setting DNS with resolvectl

Matthew R Kasun 3 years ago
parent
commit
a6429c883c
2 changed files with 6 additions and 18 deletions
  1. 1 3
      netclient/ncutils/netclientutils_linux.go
  2. 5 15
      netclient/wireguard/common.go

+ 1 - 3
netclient/ncutils/netclientutils_linux.go

@@ -34,7 +34,7 @@ func GetEmbedded() error {
 }
 }
 
 
 // CreateWireGuardConf - creates a user space WireGuard conf
 // CreateWireGuardConf - creates a user space WireGuard conf
-func CreateWireGuardConf(node *models.Node, privatekey string, listenPort string, dns string, peers []wgtypes.PeerConfig) (string, error) {
+func CreateWireGuardConf(node *models.Node, privatekey string, listenPort string, peers []wgtypes.PeerConfig) (string, error) {
 	peersString, err := parsePeers(node.PersistentKeepalive, peers)
 	peersString, err := parsePeers(node.PersistentKeepalive, peers)
 	var listenPortString, postDownString, postUpString string
 	var listenPortString, postDownString, postUpString string
 	if node.MTU <= 0 {
 	if node.MTU <= 0 {
@@ -56,7 +56,6 @@ func CreateWireGuardConf(node *models.Node, privatekey string, listenPort string
 	}
 	}
 	config := fmt.Sprintf(`[Interface]
 	config := fmt.Sprintf(`[Interface]
 Address = %s
 Address = %s
-DNS = %s
 PrivateKey = %s
 PrivateKey = %s
 MTU = %s
 MTU = %s
 %s
 %s
@@ -67,7 +66,6 @@ MTU = %s
 
 
 `,
 `,
 		node.Address+"/32",
 		node.Address+"/32",
-		dns,
 		privatekey,
 		privatekey,
 		strconv.Itoa(int(node.MTU)),
 		strconv.Itoa(int(node.MTU)),
 		postDownString,
 		postDownString,

+ 5 - 15
netclient/wireguard/common.go

@@ -4,7 +4,6 @@ import (
 	"errors"
 	"errors"
 	"io/ioutil"
 	"io/ioutil"
 	"log"
 	"log"
-	"os/exec"
 	"runtime"
 	"runtime"
 	"strconv"
 	"strconv"
 	"strings"
 	"strings"
@@ -119,7 +118,6 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
 		return err
 		return err
 	}
 	}
 	nodecfg := modcfg.Node
 	nodecfg := modcfg.Node
-	servercfg := modcfg.Server
 
 
 	if err != nil {
 	if err != nil {
 		log.Fatalf("failed to open client: %v", err)
 		log.Fatalf("failed to open client: %v", err)
@@ -136,22 +134,11 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
 	if node.Address == "" {
 	if node.Address == "" {
 		log.Fatal("no address to configure")
 		log.Fatal("no address to configure")
 	}
 	}
-	var nameserver string
-	if ncutils.IsLinux() {
-		if _, err := exec.LookPath("resolvconf"); err != nil {
-			ncutils.PrintLog("resolvconf not present", 2)
-			ncutils.PrintLog("unable to configure DNS automatically, disabling automated DNS management", 2)
-			node.DNSOn = "no"
-		}
-	}
-	if node.DNSOn == "yes" {
-		nameserver = servercfg.CoreDNSAddr
-	}
 	var newConf string
 	var newConf string
 	if node.UDPHolePunch != "yes" {
 	if node.UDPHolePunch != "yes" {
-		newConf, _ = ncutils.CreateWireGuardConf(node, key.String(), strconv.FormatInt(int64(node.ListenPort), 10), nameserver, peers)
+		newConf, _ = ncutils.CreateWireGuardConf(node, key.String(), strconv.FormatInt(int64(node.ListenPort), 10), peers)
 	} else {
 	} else {
-		newConf, _ = ncutils.CreateWireGuardConf(node, key.String(), "", nameserver, peers)
+		newConf, _ = ncutils.CreateWireGuardConf(node, key.String(), "", peers)
 	}
 	}
 	confPath := ncutils.GetNetclientPathSpecific() + ifacename + ".conf"
 	confPath := ncutils.GetNetclientPathSpecific() + ifacename + ".conf"
 	ncutils.PrintLog("writing wg conf file to: "+confPath, 1)
 	ncutils.PrintLog("writing wg conf file to: "+confPath, 1)
@@ -260,6 +247,9 @@ func SetWGConfig(network string, peerupdate bool) error {
 	} else {
 	} else {
 		err = InitWireguard(&nodecfg, privkey, peers, hasGateway, gateways, false)
 		err = InitWireguard(&nodecfg, privkey, peers, hasGateway, gateways, false)
 	}
 	}
+	if nodecfg.DNSOn == "yes" {
+		_ = local.UpdateDNS(nodecfg.Interface, nodecfg.Network, servercfg.CoreDNSAddr)
+	}
 	return err
 	return err
 }
 }