[pve-devel] [PATCH installer 1/3] run env: fix dhcp-set hostname containing local domain
Christoph Heiss
c.heiss at proxmox.com
Tue Jul 15 15:55:39 CEST 2025
According to RFC 2132 section 3.14 [0], the hostname _can_ also include the
local domain name. Strip the suffix it before storing it into the
runtime environment.
Reported on the community forum [1].
[0] https://www.rfc-editor.org/rfc/rfc2132#section-3.14
[1] https://forum.proxmox.com/threads/auto-install-fetching-fqdn-through-dhcp-does-not-set-search-domain-correctly.168369/
Fixes: bda1cdf ("run env: retrieve and store hostname from DHCP lease if available")
Signed-off-by: Christoph Heiss <c.heiss at proxmox.com>
---
Proxmox/Install/RunEnv.pm | 7 ++++++-
Proxmox/Sys/Net.pm | 12 ++++++++----
2 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/Proxmox/Install/RunEnv.pm b/Proxmox/Install/RunEnv.pm
index cdd7992..ce89346 100644
--- a/Proxmox/Install/RunEnv.pm
+++ b/Proxmox/Install/RunEnv.pm
@@ -292,7 +292,12 @@ sub query_installation_environment : prototype() {
};
# avoid serializing out null or an empty string, that can trip up the UIs
- if (my $fqdn = Proxmox::Sys::Net::get_dhcp_fqdn()) {
+ if (my $fqdn = Proxmox::Sys::Net::get_dhcp_hostname()) {
+ if (defined($output->{network}->{dns}->{domain})) {
+ # strip domain name suffix, if possible
+ $fqdn =~ s/\.$output->{network}->{dns}->{domain}//;
+ }
+
$output->{network}->{hostname} = $fqdn;
}
diff --git a/Proxmox/Sys/Net.pm b/Proxmox/Sys/Net.pm
index 38aab0e..6fe99ec 100644
--- a/Proxmox/Sys/Net.pm
+++ b/Proxmox/Sys/Net.pm
@@ -204,12 +204,16 @@ sub udevadm_netdev_details {
return $result;
}
-# Tries to detect the FQDN hostname for this system via DHCP, if available.
+# Tries to detect the hostname for this system given via DHCP, if available.
+# The hostname _might_ also include the local domain name, depending on the
+# concrete DHCP server implementation.
+#
+# DHCP servers can set option 12 to inform the client about it's hostname [0].
+# dhclient dumps all options set by the DHCP server it in lease file, so just
+# read it from there.
#
-# DHCP server can set option 12 to inform the client about it's hostname [0]. dhclient dumps all
-# options set by the DHCP server it in lease file, so just read it from there.
# [0] RFC 2132, section 3.14
-sub get_dhcp_fqdn : prototype() {
+sub get_dhcp_hostname : prototype() {
my $leasefile = '/var/lib/dhcp/dhclient.leases';
return if !-f $leasefile;
--
2.49.0
More information about the pve-devel
mailing list