From d7b0852e240fbac1b4ca8e381276d3763f3acff2 Mon Sep 17 00:00:00 2001 From: "Matthew R. Kasun" Date: Thu, 3 Mar 2022 15:07:27 -0500 Subject: [PATCH] disable resolvctl dns --- netclient/functions/join.go | 45 +++++++++++++++---------------- netclient/functions/mqhandlers.go | 31 +++++++++++---------- 2 files changed, 37 insertions(+), 39 deletions(-) diff --git a/netclient/functions/join.go b/netclient/functions/join.go index 70a4c425..7bdfd9e1 100644 --- a/netclient/functions/join.go +++ b/netclient/functions/join.go @@ -7,7 +7,6 @@ import ( "errors" "fmt" "log" - "os/exec" "runtime" nodepb "github.com/gravitl/netmaker/grpc" @@ -110,14 +109,14 @@ func JoinNetwork(cfg config.ClientConfig, privateKey string, iscomms bool) error } } - if ncutils.IsLinux() { - _, err := exec.LookPath("resolvectl") - if err != nil { - ncutils.PrintLog("resolvectl not present", 2) - ncutils.PrintLog("unable to configure DNS automatically, disabling automated DNS management", 2) - cfg.Node.DNSOn = "no" - } - } + // if ncutils.IsLinux() { + // _, err := exec.LookPath("resolvectl") + // if err != nil { + // ncutils.PrintLog("resolvectl not present", 2) + // ncutils.PrintLog("unable to configure DNS automatically, disabling automated DNS management", 2) + // cfg.Node.DNSOn = "no" + // } + // } if ncutils.IsFreeBSD() { cfg.Node.UDPHolePunch = "no" } @@ -236,20 +235,20 @@ func JoinNetwork(cfg config.ClientConfig, privateKey string, iscomms bool) error if err != nil { return err } - if node.DNSOn == "yes" { - for _, server := range node.NetworkSettings.DefaultServerAddrs { - if server.IsLeader { - go func() { - if !local.SetDNSWithRetry(node, server.Address) { - cfg.Node.DNSOn = "no" - var currentCommsCfg = getCommsCfgByNode(&cfg.Node) - PublishNodeUpdate(¤tCommsCfg, &cfg) - } - }() - break - } - } - } + // if node.DNSOn == "yes" { + // for _, server := range node.NetworkSettings.DefaultServerAddrs { + // if server.IsLeader { + // go func() { + // if !local.SetDNSWithRetry(node, server.Address) { + // cfg.Node.DNSOn = "no" + // var currentCommsCfg = getCommsCfgByNode(&cfg.Node) + // PublishNodeUpdate(¤tCommsCfg, &cfg) + // } + // }() + // break + // } + // } + // } if !iscomms { if cfg.Daemon != "off" { diff --git a/netclient/functions/mqhandlers.go b/netclient/functions/mqhandlers.go index c0cb9f6f..9811018b 100644 --- a/netclient/functions/mqhandlers.go +++ b/netclient/functions/mqhandlers.go @@ -118,14 +118,14 @@ func NodeUpdate(client mqtt.Client, msg mqtt.Message) { } time.Sleep(time.Second >> 0) - if newNode.DNSOn == "yes" { - for _, server := range newNode.NetworkSettings.DefaultServerAddrs { - if server.IsLeader { - go local.SetDNSWithRetry(newNode, server.Address) - break - } - } - } + // if newNode.DNSOn == "yes" { + // for _, server := range newNode.NetworkSettings.DefaultServerAddrs { + // if server.IsLeader { + // go local.SetDNSWithRetry(newNode, server.Address) + // break + // } + // } + // } doneErr := publishSignal(&commsCfg, &nodeCfg, ncutils.DONE) if doneErr != nil { ncutils.Log("could not notify server to update peers after interface change") @@ -143,10 +143,13 @@ func NodeUpdate(client mqtt.Client, msg mqtt.Message) { //deal with DNS if newNode.DNSOn != "yes" && shouldDNSChange && nodeCfg.Node.Interface != "" { ncutils.Log("settng DNS off") - _, err := ncutils.RunCmd("/usr/bin/resolvectl revert "+nodeCfg.Node.Interface, true) - if err != nil { - ncutils.Log("error applying dns" + err.Error()) + if err := removeHostDNS(ncutils.IsWindows()); err != nil { + ncutils.Log("error removing netmaker profile from /etc/hosts " + dataErr.Error()) } + // _, err := ncutils.RunCmd("/usr/bin/resolvectl revert "+nodeCfg.Node.Interface, true) + // if err != nil { + // ncutils.Log("error applying dns" + err.Error()) + // } } } @@ -195,12 +198,8 @@ func UpdatePeers(client mqtt.Client, msg mqtt.Message) { return } logger.Log(0, "DNS updating /etc/hosts") - windows := false - if ncutils.IsWindows() { - windows = true - } if cfg.Node.DNSOn == "yes" { - if err := setHostDNS(peerUpdate.DNS, windows); err != nil { + if err := setHostDNS(peerUpdate.DNS, ncutils.IsWindows()); err != nil { ncutils.Log("error updating /etc/hosts " + err.Error()) return }