Skip to content

Commit

Permalink
network: disable DNS server when not needed
Browse files Browse the repository at this point in the history
Libvirt automatically starts a DNS server for a virtual network, even if
there is no forwarding or local domains configured. This by itself is
perhaps wasteful, but not an issue.

The issue arises in tests using multiple networks per VM. Some distributions
(for example: CentOS 7) configure DNS resolution without any coordination,
leading to a situation where /etc/resolv.conf points to the DNS server on
the secondary network. Tests may want stop/start these secondary interfaces
at will, leading to situations where DNS queries can't be resolved because
the DNS server is temporarily not reachable.

The solution implemented here explicitly disables the DNS server when both
no forward mode and no local domain was specified. For tests this means
that the DNS server is basically always the one on the access network (which
presumably has a forward mode configured).
  • Loading branch information
WanzenBug committed Jul 26, 2022
1 parent 1de3838 commit 7019f56
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cmd/network_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,19 @@ func networkAddCommand() *cobra.Command {
}
}

var dnsDesc *libvirtxml.NetworkDNS
if domain == "" && forward == "" {
dnsDesc = &libvirtxml.NetworkDNS{
Enable: "no",
}
}

desc := libvirtxml.Network{
Name: args[0],
Forward: forwardDesc,
IPs: addressesDesc,
Domain: domainDesc,
DNS: dnsDesc,
}

err = v.NetworkAdd(desc)
Expand Down

0 comments on commit 7019f56

Please sign in to comment.