From 7019f56ef0ba76280e54913cdf3c22a6083692f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20=22WanzenBug=22=20Wanzenb=C3=B6ck?= Date: Tue, 26 Jul 2022 14:17:42 +0200 Subject: [PATCH] network: disable DNS server when not needed 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). --- cmd/network_add.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cmd/network_add.go b/cmd/network_add.go index 4407c84..531f59b 100644 --- a/cmd/network_add.go +++ b/cmd/network_add.go @@ -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)