From: Christoph Heiss <c.heiss@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH installer 1/3] run env: fix dhcp-set hostname containing local domain
Date: Tue, 15 Jul 2025 15:55:39 +0200 [thread overview]
Message-ID: <20250715135620.1023136-2-c.heiss@proxmox.com> (raw)
In-Reply-To: <20250715135620.1023136-1-c.heiss@proxmox.com>
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@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
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
next prev parent reply other threads:[~2025-07-15 13:56 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-15 13:55 [pve-devel] [PATCH installer 0/3] run env, auto: fix dhcp hostname/domain retrieval Christoph Heiss
2025-07-15 13:55 ` Christoph Heiss [this message]
2025-07-15 13:55 ` [pve-devel] [PATCH installer 2/3] auto: answer: deserialize empty domain name as `None` Christoph Heiss
2025-07-15 13:55 ` [pve-devel] [PATCH installer 3/3] install: run `make tidy` Christoph Heiss
2025-07-15 14:32 ` [pve-devel] applied: [PATCH installer 0/3] run env, auto: fix dhcp hostname/domain retrieval Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250715135620.1023136-2-c.heiss@proxmox.com \
--to=c.heiss@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox