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 <me@dualfroz.com>
This commit is contained in:
dualfroz committed 2026-10-02 16:37:36 +02:00
1 parent 2c458b3b43
commit 5bbb9a8f1d
1 file changed
+5 -2
+5 -2
View File
@@ -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;
}
}
}