From 5bbb9a8f1dacd20d958219b5909958e2e9c22795 Mon Sep 17 00:00:00 2001 From: Michal Fox Date: Fri, 2 Oct 2026 16:37:36 +0200 Subject: [PATCH] fix #7036: cloud-init: configdrive2: fix DNS settings The network configuration for configdrive2 is in the format of /etc/network/interfaces, where the DNS settings are configured with the 'dns-nameservers' and 'dns-search' options in an interface stanza. But they were written with an underscore instead of a dash, and right after the stanza of the loopback interface, so cloud-init ignored them and the configured nameservers and search domains never ended up in the guest. Just using the correct option names would not be enough, as cloud-init does not apply the DNS settings of the loopback interface when rendering the configuration with netplan, for example. Write the options with a dash and add them to the stanzas of the statically configured interfaces, like it is already done for the cloudbase-init configuration. Signed-off-by: Michal Fox --- src/PVE/QemuServer/Cloudinit.pm | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/PVE/QemuServer/Cloudinit.pm b/src/PVE/QemuServer/Cloudinit.pm index d8eb1ca..7fa5041 100644 --- a/src/PVE/QemuServer/Cloudinit.pm +++ b/src/PVE/QemuServer/Cloudinit.pm @@ -201,14 +201,15 @@ sub configdrive2_network { my $content = "auto lo\n"; $content .= "iface lo inet loopback\n\n"; + my $dns_options = ''; my ($searchdomains, $nameservers) = get_dns_conf($conf); if ($nameservers && @$nameservers) { $nameservers = join(' ', @$nameservers); - $content .= " dns_nameservers $nameservers\n"; + $dns_options .= " dns-nameservers $nameservers\n"; } if ($searchdomains && @$searchdomains) { $searchdomains = join(' ', @$searchdomains); - $content .= " dns_search $searchdomains\n"; + $dns_options .= " dns-search $searchdomains\n"; } my @ifaces = grep { /^net(\d+)$/ } keys %$conf; @@ -228,6 +229,7 @@ sub configdrive2_network { $content .= " address $addr\n"; $content .= " netmask $mask\n"; $content .= " gateway $net->{gw}\n" if $net->{gw}; + $content .= $dns_options; } } if ($net->{ip6}) { @@ -239,6 +241,7 @@ sub configdrive2_network { $content .= " address $addr\n"; $content .= " netmask $mask\n"; $content .= " gateway $net->{gw6}\n" if $net->{gw6}; + $content .= $dns_options; } } }