Skip to content

Commit

Permalink
fix: joining multiple dns server lists (#2506)
Browse files Browse the repository at this point in the history
* fix: joining multiple dns server lists

* address comments

* add 0 check
  • Loading branch information
vakalapa authored and jpayne3506 committed Feb 15, 2024
1 parent 2ffa5ef commit 8ab25c8
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions network/network_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,21 @@ func addDNSServers(ifName string, dnsServers []string) (string, error) {
return osVersion, err
}

if len(dnsServers) == 0 {
log.Printf("WARN: No dns servers to add")
return "", nil
}

var cmd string
switch {
case strings.HasPrefix(osVersion, Ubuntu22):
cmd = fmt.Sprintf("resolvectl dns %s %s", ifName, strings.Join(dnsServers, " "))
default:
cmd = fmt.Sprintf("systemd-resolve --interface %s %s", ifName, strings.Join(dnsServers, "--set-dns "))
serverList := ""
for _, server := range dnsServers {
serverList = serverList + " --set-dns " + server
}
cmd = fmt.Sprintf("systemd-resolve --interface %s %s", ifName, serverList)
}
return cmd, nil
}
Expand Down Expand Up @@ -415,10 +424,11 @@ func applyDnsConfig(extIf *externalInterface, ifName string) error {
if err != nil {
return errors.Wrap(err, "Error generating add DNS Servers cmd")
}

_, err = p.ExecuteCommand(cmd)
if err != nil {
return errors.Wrapf(err, "Error executing add DNS Servers with cmd %s", cmd)
if cmd != "" {
_, err = p.ExecuteCommand(cmd)
if err != nil {
return errors.Wrapf(err, "Error executing add DNS Servers with cmd %s", cmd)
}
}
}

Expand Down

0 comments on commit 8ab25c8

Please sign in to comment.