From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id BCB141FF09F for ; Tue, 01 Dec 2026 16:34:23 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 4EAF8216BD; Tue, 01 Dec 2026 16:34:20 +0100 (CET) From: Filip Schauer To: pve-devel@lists.proxmox.com Subject: [PATCH container v3 2/2] fix #7388: prefer container DNS config over host-managed DHCP Date: Tue, 1 Dec 2026 16:33:44 +0100 Message-ID: <20261201153346.163922-3-f.schauer@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261201153346.163922-1-f.schauer@proxmox.com> References: <20261201153346.163922-1-f.schauer@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1796139255601 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.150 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: QMU4LJ4LGKEBXEMTQBQHLIZOEZ362UZL X-Message-ID-Hash: QMU4LJ4LGKEBXEMTQBQHLIZOEZ362UZL X-MailFrom: f.schauer@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: 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 by setting IGNORE_DHCP_NAMESERVERS or IGNORE_DHCP_SEARCHDOMAINS in the environment of dhclient-script if the container config sets nameserver or searchdomain respectively. Signed-off-by: Filip Schauer --- src/PVE/LXC.pm | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm index 237b298..ed4c0a4 100644 --- a/src/PVE/LXC.pm +++ b/src/PVE/LXC.pm @@ -1349,12 +1349,22 @@ sub get_interfaces { } sub manage_dhclient { - my ($action, $vmid, $ipversion, $eth, $rootdir) = @_; + my ($action, $vmid, $conf, $ipversion, $eth, $rootdir) = @_; File::Path::make_path("/var/lib/lxc/$vmid/hook") if $action eq 'start'; my $pidfile = "/var/lib/lxc/$vmid/hook/dhclient$ipversion-$eth.pid"; my $leasefile = "/var/lib/lxc/$vmid/hook/dhclient$ipversion-$eth.leases"; my $scriptfile = '/usr/share/lxc/hooks/dhclient-script'; + + # The DNS settings of the container config take precedence over the ones from the DHCP server. + my @dns_env; + if ($action eq 'start') { + my @nameservers = PVE::Tools::split_list($conf->{nameserver}); + my @searchdomains = PVE::Tools::split_list($conf->{searchdomain}); + push @dns_env, '-e', "IGNORE_DHCP_NAMESERVERS=1" if @nameservers; + push @dns_env, '-e', "IGNORE_DHCP_SEARCHDOMAINS=1" if @searchdomains; + } + run_in_ct_namespaces( $vmid, ['net', 'uts'], @@ -1371,6 +1381,7 @@ sub manage_dhclient { $leasefile, '-e', "ROOTFS=$rootdir", + @dns_env, '-sf', $scriptfile, $eth, @@ -1428,10 +1439,10 @@ sub update_ipconfig { my $is_real_ip = ($newip && $newip !~ /^(?:auto|dhcp|manual)$/); if ($change_ip) { if ($newnet->{'host-managed'} && $newip && $newip eq 'dhcp') { - manage_dhclient('start', $vmid, $ipversion, $eth, $rootdir); + manage_dhclient('start', $vmid, $conf, $ipversion, $eth, $rootdir); } if ($optdata->{'host-managed'} && $oldip && $oldip eq 'dhcp') { - manage_dhclient('stop', $vmid, $ipversion, $eth, $rootdir); + manage_dhclient('stop', $vmid, $conf, $ipversion, $eth, $rootdir); } if ($is_real_ip) { @@ -1442,7 +1453,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, $rootdir); } # step 2: replace gateway @@ -3319,12 +3330,12 @@ sub vm_start { my $rootdir = "/proc/$pid/root"; 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 $@; } 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 $@; } -- 2.47.3