mirror of
https://github.com/gravitl/netmaker.git
synced 2025-11-18 16:08:44 +08:00
dns per network
This commit is contained in:
parent
0abba58bfb
commit
11e0bd20d3
1 changed files with 8 additions and 8 deletions
|
|
@ -142,7 +142,7 @@ func NodeUpdate(client mqtt.Client, msg mqtt.Message) {
|
|||
//deal with DNS
|
||||
if newNode.DNSOn != "yes" && shouldDNSChange && nodeCfg.Node.Interface != "" {
|
||||
ncutils.Log("settng DNS off")
|
||||
if err := removeHostDNS(ncutils.IsWindows()); err != nil {
|
||||
if err := removeHostDNS(nodeCfg.Network, ncutils.IsWindows()); err != nil {
|
||||
ncutils.Log("error removing netmaker profile from /etc/hosts " + err.Error())
|
||||
}
|
||||
// _, err := ncutils.RunCmd("/usr/bin/resolvectl revert "+nodeCfg.Node.Interface, true)
|
||||
|
|
@ -202,19 +202,19 @@ func UpdatePeers(client mqtt.Client, msg mqtt.Message) {
|
|||
// return
|
||||
//}
|
||||
if cfg.Node.DNSOn == "yes" {
|
||||
if err := setHostDNS(peerUpdate.DNS, ncutils.IsWindows()); err != nil {
|
||||
if err := setHostDNS(peerUpdate.DNS, cfg.Node.Network, ncutils.IsWindows()); err != nil {
|
||||
ncutils.Log("error updating /etc/hosts " + err.Error())
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if err := removeHostDNS(ncutils.IsWindows()); err != nil {
|
||||
ncutils.Log("error removing netmaker profile from /etc/hosts " + err.Error())
|
||||
if err := removeHostDNS(cfg.Node.Network, ncutils.IsWindows()); err != nil {
|
||||
ncutils.Log("error removing profile from /etc/hosts " + err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func setHostDNS(dns string, windows bool) error {
|
||||
func setHostDNS(dns, network string, windows bool) error {
|
||||
log.Println(dns)
|
||||
etchosts := "/etc/hosts"
|
||||
if windows {
|
||||
|
|
@ -229,7 +229,7 @@ func setHostDNS(dns string, windows bool) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
profile.Name = "netmaker"
|
||||
profile.Name = network
|
||||
profile.Status = types.Enabled
|
||||
if err := hosts.ReplaceProfile(profile); err != nil {
|
||||
return err
|
||||
|
|
@ -240,7 +240,7 @@ func setHostDNS(dns string, windows bool) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func removeHostDNS(windows bool) error {
|
||||
func removeHostDNS(network string, windows bool) error {
|
||||
etchosts := "/etc/hosts"
|
||||
if windows {
|
||||
etchosts = "c:\\windows\\system32\\drivers\\etc\\hosts"
|
||||
|
|
@ -249,7 +249,7 @@ func removeHostDNS(windows bool) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := hosts.RemoveProfile("netmaker"); err != nil {
|
||||
if err := hosts.RemoveProfile(network); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := hosts.Flush(); err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue