* [PATCH lxc v3 1/2] patch dhclient-script to allow ignoring DNS settings
2026-12-01 15:33 [PATCH container/lxc v3 0/2] fix #7388: prefer container DNS config over host-managed DHCP Filip Schauer
@ 2026-12-01 15:33 ` Filip Schauer
2026-12-01 15:33 ` [PATCH container v3 2/2] fix #7388: prefer container DNS config over host-managed DHCP Filip Schauer
1 sibling, 0 replies; 3+ messages in thread
From: Filip Schauer @ 2026-12-01 15:33 UTC (permalink / raw)
To: pve-devel
Patch dhclient-script such that DNS settings offered by the DHCP server
can be ignored.
Signed-off-by: Filip Schauer <f.schauer@proxmox.com>
---
...fig-deny-rw-mounting-of-sys-and-proc.patch | 2 +-
...-PVE-Config-attach-always-use-getent.patch | 2 +-
...-script-set-RFC3442-classless-routes.patch | 2 +-
...4-dhclient-script-allow-ignoring-dns.patch | 63 +++++++++++++++++++
debian/patches/series | 1 +
5 files changed, 67 insertions(+), 3 deletions(-)
create mode 100644 debian/patches/pve/0004-dhclient-script-allow-ignoring-dns.patch
diff --git a/debian/patches/pve/0001-PVE-Config-deny-rw-mounting-of-sys-and-proc.patch b/debian/patches/pve/0001-PVE-Config-deny-rw-mounting-of-sys-and-proc.patch
index d2194d6..9096f72 100644
--- a/debian/patches/pve/0001-PVE-Config-deny-rw-mounting-of-sys-and-proc.patch
+++ b/debian/patches/pve/0001-PVE-Config-deny-rw-mounting-of-sys-and-proc.patch
@@ -1,7 +1,7 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= <f.gruenbichler@proxmox.com>
Date: Wed, 9 Nov 2016 09:14:26 +0100
-Subject: [PATCH 1/3] PVE: [Config] deny rw mounting of /sys and /proc
+Subject: [PATCH 1/4] PVE: [Config] deny rw mounting of /sys and /proc
Note that we don't actually make use of this anymore, since
we switched to the generated profiles which already do this.
diff --git a/debian/patches/pve/0002-PVE-Config-attach-always-use-getent.patch b/debian/patches/pve/0002-PVE-Config-attach-always-use-getent.patch
index 190837d..7a09d52 100644
--- a/debian/patches/pve/0002-PVE-Config-attach-always-use-getent.patch
+++ b/debian/patches/pve/0002-PVE-Config-attach-always-use-getent.patch
@@ -1,7 +1,7 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Wolfgang Bumiller <w.bumiller@proxmox.com>
Date: Tue, 13 Aug 2019 13:57:22 +0200
-Subject: [PATCH 2/3] PVE: [Config] attach: always use getent
+Subject: [PATCH 2/4] PVE: [Config] attach: always use getent
In debian buster, some libnss plugins (if installed) can
cause getpwent to segfault instead of erroring out cleanly.
diff --git a/debian/patches/pve/0003-dhclient-script-set-RFC3442-classless-routes.patch b/debian/patches/pve/0003-dhclient-script-set-RFC3442-classless-routes.patch
index 9dd2fb9..d466c76 100644
--- a/debian/patches/pve/0003-dhclient-script-set-RFC3442-classless-routes.patch
+++ b/debian/patches/pve/0003-dhclient-script-set-RFC3442-classless-routes.patch
@@ -1,7 +1,7 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Filip Schauer <f.schauer@proxmox.com>
Date: Wed, 3 Dec 2025 15:03:50 +0100
-Subject: [PATCH 3/3] dhclient-script: set RFC3442 classless routes
+Subject: [PATCH 3/4] dhclient-script: set RFC3442 classless routes
Due to the removal of hooks in the LXC fork of dhclient-script, the
rfc3442-classless-routes hook did not run. As a result, classless static
diff --git a/debian/patches/pve/0004-dhclient-script-allow-ignoring-dns.patch b/debian/patches/pve/0004-dhclient-script-allow-ignoring-dns.patch
new file mode 100644
index 0000000..249044d
--- /dev/null
+++ b/debian/patches/pve/0004-dhclient-script-allow-ignoring-dns.patch
@@ -0,0 +1,63 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Filip Schauer <f.schauer@proxmox.com>
+Date: Tue, 1 Dec 2026 15:28:13 +0100
+Subject: [PATCH 4/4] dhclient-script: allow ignoring DNS settings
+
+IF IGNORE_DHCP_SEARCHDOMAINS or IGNORE_DHCP_NAMESERVERS are set in the
+environment of the script, ignore the respective DNS settings offered by
+the DHCP server.
+
+Signed-off-by: Filip Schauer <f.schauer@proxmox.com>
+---
+ hooks/dhclient-script | 23 +++++++++++++++++++++++
+ 1 file changed, 23 insertions(+)
+
+diff --git a/hooks/dhclient-script b/hooks/dhclient-script
+index c87792707..627a5d575 100755
+--- a/hooks/dhclient-script
++++ b/hooks/dhclient-script
+@@ -45,11 +45,30 @@ make_resolv_conf() {
+ local resolv_conf="${ROOTFS}/etc/resolv.conf"
+ local new_resolv_conf="${ROOTFS}/etc/resolv.conf.dhclient-new"
+
++ local old_search=""
++ if [ -n "$IGNORE_DHCP_SEARCHDOMAINS" ]; then
++ if [ -f "$resolv_conf" ]; then
++ old_search=$(sed -n '/^[[:space:]]*\(search\|domain\)[[:space:]]/p' "$resolv_conf")
++ fi
++ local new_domain_name=""
++ local new_domain_search=""
++ local new_dhcp6_domain_search=""
++ fi
++
++ if [ -n "$IGNORE_DHCP_NAMESERVERS" ]; then
++ local new_domain_name_servers=""
++ local new_dhcp6_name_servers=""
++ fi
++
+ # DHCPv4
+ if [ -n "$new_domain_search" ] || [ -n "$new_domain_name" ] ||
+ [ -n "$new_domain_name_servers" ]; then
+ rm -f $new_resolv_conf
+
++ if [ -n "$old_search" ]; then
++ echo "$old_search" >>$new_resolv_conf
++ fi
++
+ if [ -n "$new_domain_name" ]; then
+ echo domain ${new_domain_name%% *} >>$new_resolv_conf
+ fi
+@@ -89,6 +108,10 @@ make_resolv_conf() {
+ elif [ -n "$new_dhcp6_domain_search" ] || [ -n "$new_dhcp6_name_servers" ]; then
+ rm -f $new_resolv_conf
+
++ if [ -n "$old_search" ]; then
++ echo "$old_search" >>$new_resolv_conf
++ fi
++
+ if [ -n "$new_dhcp6_domain_search" ]; then
+ echo "search ${new_dhcp6_domain_search}" >> $new_resolv_conf
+ fi
+--
+2.47.3
+
diff --git a/debian/patches/series b/debian/patches/series
index 8a37d9b..0025afb 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -3,5 +3,6 @@ apparmor/0002-apparmor-use-abi-directive-in-apparmor-profiles.patch
pve/0001-PVE-Config-deny-rw-mounting-of-sys-and-proc.patch
pve/0002-PVE-Config-attach-always-use-getent.patch
pve/0003-dhclient-script-set-RFC3442-classless-routes.patch
+pve/0004-dhclient-script-allow-ignoring-dns.patch
cgroupv1-warnings/0001-PVE-Revert-lxc-conf-drop-cgroup1-config-options-lxc..patch
cgroupv1-warnings/0002-PVE-ignore-cgroupv1-settings-with-a-warning.patch
--
2.47.3
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH container v3 2/2] fix #7388: prefer container DNS config over host-managed DHCP
2026-12-01 15:33 [PATCH container/lxc v3 0/2] fix #7388: prefer container DNS config over host-managed DHCP Filip Schauer
2026-12-01 15:33 ` [PATCH lxc v3 1/2] patch dhclient-script to allow ignoring DNS settings Filip Schauer
@ 2026-12-01 15:33 ` Filip Schauer
1 sibling, 0 replies; 3+ messages in thread
From: Filip Schauer @ 2026-12-01 15:33 UTC (permalink / raw)
To: pve-devel
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 <f.schauer@proxmox.com>
---
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
^ permalink raw reply related [flat|nested] 3+ messages in thread