From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id B540F1FF09F for ; Tue, 01 Dec 2026 12:36:55 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 9351421603; Tue, 01 Dec 2026 12:36:52 +0100 (CET) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Tue, 01 Dec 2026 12:36:47 +0100 Message-Id: Subject: Re: [PATCH container v2] fix #7388: prefer container DNS config over host-managed DHCP From: "Elias Huhsovitz" To: "Filip Schauer" , X-Mailer: aerc 0.20.0 References: <20261130133226.90647-1-f.schauer@proxmox.com> In-Reply-To: <20261130133226.90647-1-f.schauer@proxmox.com> X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1796125007593 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.390 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: D2QDCLTPPMULZAY2SHN64L7P6AFYXBHH X-Message-ID-Hash: D2QDCLTPPMULZAY2SHN64L7P6AFYXBHH X-MailFrom: e.huhsovitz@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Gave this a quick test with a small dnsmasq DHCP server that provides dns-server & domain-name options. The DHCP server starts using: dnsmasq --no-daemon \ --port=3D0 \ --interface=3Dvmbr88 \ --bind-interfaces \ --dhcp-range=3D10.0.88.100,10.0.88.150,12h \ --dhcp-option=3Doption:router,10.0.88.10 \ --dhcp-option=3Doption:dns-server,10.0.88.10 \ --dhcp-option=3Doption:domain-name,lan.example Container config: nameserver: 9.9.9.9 net0: name=3Deth0,bridge=3Dvmbr88,firewall=3D1,host-managed=3D1,hwaddr=3DBC= :24:11:D0:32:EA,ip=3Ddhcp,type=3Dveth searchdomain: corp.example The resulting resolv.conf: domain lan.example search lan.example corp.example. nameserver 9.9.9.9 If I understand the goal of this patch correctly, resolv.conf should contain: search corp.example nameserver 9.9.9.9 Since we want to completely disregard the settings provided by the DHCP.=20 Comments inline. On Mon Nov 30, 2026 at 2:32 PM CET, Filip Schauer wrote: > For host-managed container network interfaces using DHCP, dhclient may > overwrite /etc/resolv.conf with DNS information supplied by the DHCP > server, causing any explicitly configured nameserver/searchdomain to be > silently ignored. > > Fix this with a custom dhclient.conf that ensures the container config > takes precedence over any DNS settings offered by the DHCP server. > > Signed-off-by: Filip Schauer > --- > Changed since v1: > * Rebased onto pve-container 6.1.29 > > src/PVE/LXC.pm | 42 ++++++++++++++++++++++++++++++++++++------ > 1 file changed, 36 insertions(+), 6 deletions(-) > > diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm > index 237b298..59d0ca0 100644 > --- a/src/PVE/LXC.pm > +++ b/src/PVE/LXC.pm > @@ -1349,12 +1349,41 @@ sub get_interfaces { > } > =20 > sub manage_dhclient { > - my ($action, $vmid, $ipversion, $eth, $rootdir) =3D @_; > + my ($action, $vmid, $conf, $ipversion, $eth, $rootdir) =3D @_; > =20 > File::Path::make_path("/var/lib/lxc/$vmid/hook") if $action eq 'star= t'; > my $pidfile =3D "/var/lib/lxc/$vmid/hook/dhclient$ipversion-$eth.pid= "; > my $leasefile =3D "/var/lib/lxc/$vmid/hook/dhclient$ipversion-$eth.l= eases"; > my $scriptfile =3D '/usr/share/lxc/hooks/dhclient-script'; > + > + # Keep configfh open until dhclient has opened the file > + my $configfh; > + my @config_opts; > + > + if ($action eq 'start') { > + my $config =3D ""; > + my $base =3D '/etc/dhcp/dhclient.conf'; > + if (-f $base) { > + $config =3D PVE::Tools::file_get_contents($base) . "\n"; > + } > + > + my $ns_re =3D $ipversion =3D=3D 6 ? qr/^$IPV6RE$/ : qr/^$IPV4RE$= /; Anchoring the regex now causes IPv6 address with a zone-id to be rejected by the $IPV6RE regex. e.g. 'fe80::1%eth0'. (Even though this is a valid config in PVE). I guess the $conf->{nameserver} has to be pre-processed. Or perhaps the unanchored regex is actually the right call here, since we valide the config beforehand anyways, when changes are made. > + if (my @nameservers =3D grep { $_ =3D~ $ns_re } PVE::Tools::spli= t_list($conf->{nameserver})) { > + my $option =3D $ipversion =3D=3D 6 ? "dhcp6.name-servers" : = "domain-name-servers"; > + $config .=3D "supersede $option " . join(', ', @nameservers)= . ";\n"; > + } > + > + if (my @searchdomains =3D PVE::Tools::split_list($conf->{searchd= omain})) { > + $config .=3D "supersede " . (($ipversion =3D=3D 6) ? "dhcp6.= " : "") . "domain-search "; > + $config .=3D join(", ", map { "\"$_\"" } @searchdomains) . "= ;\n"; This doesnt not get applied correctly when the DHCP provides option 15 (domain-name). You can try something like=20 if ($ipversion =3D=3D 4) { $config .=3D "supersede domain-name \"\";\n"; } So that in /usr/share/lxc/hooks/dhclient-script:make_resolv_conf() the variable $new_domain_search is empty. But I just used this appraoch to confirmed that make_resolv_conf() lines 49-70 are the cause. Perhaps we can think of a better long-term solution. > + } > + > + open($configfh, '+>', undef) or die "failed to create dhclient c= onfig: $!\n"; > + print $configfh $config; > + $configfh->flush(); > + @config_opts =3D ('-cf', "/proc/$$/fd/" . fileno($configfh)); > + } > + > run_in_ct_namespaces( > $vmid, > ['net', 'uts'], > @@ -1373,6 +1402,7 @@ sub manage_dhclient { > "ROOTFS=3D$rootdir", > '-sf', > $scriptfile, > + @config_opts, > $eth, > ], > ); > @@ -1428,10 +1458,10 @@ sub update_ipconfig { > my $is_real_ip =3D ($newip && $newip !~ /^(?:auto|dhcp|manual)$/= ); > if ($change_ip) { > if ($newnet->{'host-managed'} && $newip && $newip eq 'dhcp')= { > - manage_dhclient('start', $vmid, $ipversion, $eth, $rootd= ir); > + manage_dhclient('start', $vmid, $conf, $ipversion, $eth,= $rootdir); > } > if ($optdata->{'host-managed'} && $oldip && $oldip eq 'dhcp'= ) { > - manage_dhclient('stop', $vmid, $ipversion, $eth, $rootdi= r); > + manage_dhclient('stop', $vmid, $conf, $ipversion, $eth, = $rootdir); > } > =20 > if ($is_real_ip) { > @@ -1442,7 +1472,7 @@ sub update_ipconfig { > } > } > } elsif ($optdata->{'host-managed'} && !$newnet->{'host-managed'= }) { > - manage_dhclient('stop', $vmid, $ipversion, $eth, $rootdir); > + manage_dhclient('stop', $vmid, $conf, $ipversion, $eth, $roo= tdir); > } > =20 > # step 2: replace gateway > @@ -3319,12 +3349,12 @@ sub vm_start { > my $rootdir =3D "/proc/$pid/root"; > =20 > for my $eth (@managed_dhcpv4_interfaces) { > - eval { manage_dhclient('start', $vmid, 4, $eth, $rootdir) }; > + eval { manage_dhclient('start', $vmid, $conf, 4, $eth, $rootdir)= }; > PVE::RESTEnvironment::log_warn("DHCP failed - $@") if $@; > } > =20 > for my $eth (@managed_dhcpv6_interfaces) { > - eval { manage_dhclient('start', $vmid, 6, $eth, $rootdir) }; > + eval { manage_dhclient('start', $vmid, $conf, 6, $eth, $rootdir)= }; > PVE::RESTEnvironment::log_warn("DHCP failed - $@") if $@; > } > =20