I realize you consider this solved and have found a workaround of sorts. While you had a limited concern about the hostname value as reflected in your bash prompt and setting the 'hostname-mode=off' fixed that, the bigger question is why NetworkManager does not intially recognize that you have a static hostname and instead is configuring a transient hostname:
Code: Select all
hostname-mode
Set the management mode of the hostname. This parameter will affect only the transient hostname. If a valid static hostname is set, NetworkManager will skip the update of the hostname despite the value of this option. A hostname empty or equal to '(none)' is considered invalid . . .
none: NetworkManager will not manage the transient hostname and will never set it.
https://manpages.debian.org/unstable/ne ... .5.en.html
Instead of finding and using the locally configured static hostname, your machine is configured to ask the DHCP server for the hostname. The transient hostname is set to 'localhost' either by design or defaults to 'localhost' if it is not given by the DHCP server. The 'hostmode-mode=off' entry does prevent asking the DHCP server for the hostname but it should only do that if configured to do so.
It sounds like this is specific to your network setup.
This would make sense if:
A) You did not set the value for the hostname locally (i.e. /etc/localhost was empty)
B) Your host machine is inside of a VM or container or using a network bridge
C) There is more than one network manager or DHCP service running on the the machine which conflicts with NetworkManager.
D) Your system is configured not to send the static hostname to the DHCP server and to instead ask the DHCP server for the hostname.
I am providing additional information to consider should you or someone else using systemd with a similar problem that stumbles upon this decide to further inspect their network setup with regards to DHCP hostname.
NetworkManager relies on the systemd-hostnamed service to read and write the static host name as stored in the /etc/hostname. It would be useful to check the status of the systemd-hostnamed service:
Code: Select all
systemctl status systemd-hostnamed
If the service was loading at boot and working correctly, the output would look something similar to:
Code: Select all
○ systemd-hostnamed.service - Hostname Service
Loaded: loaded (/usr/lib/systemd/system/systemd-hostnamed.service; static)
Active: inactive (dead) since Fri 2025-11-21 02:53:21 EST; 7min ago
Duration: 30.041s
Invocation: 1642684f79664249b246e83eed986c63
TriggeredBy: ● systemd-hostnamed.socket
Docs: man:systemd-hostnamed.service(8)
man:hostname(5)
man:machine-info(5)
man:org.freedesktop.hostname1(5)
Process: 221063 ExecStart=/usr/lib/systemd/systemd-hostnamed (code=exited, status=0/SUCCESS)
Main PID: 221063 (code=exited, status=0/SUCCESS)
Status: "Shutting down..."
Mem peak: 2.4M
CPU: 26ms
Nov 21 02:52:51 tux systemd[1]: Starting Hostname Service...
Nov 21 02:52:51 tux systemd[1]: Started Hostname Service.
Nov 21 02:53:21 tux systemd[1]: systemd-hostnamed.service: Deactivated successfully.
When under those conditions, It might also be insightful to see if the output of:
list both a static hostname and a transient hostname:
Code: Select all
Static hostname: localhost.localdomain
Transient hostname: home.domain.example
(My output only lists a static hostname.)
For configuration of network connections I only have NetworkManager installed and built without dhclient or dhcpcd :
Code: Select all
- - dhclient : Use dhclient from net-misc/dhcp for
getting an IP via DHCP
- - dhcpcd : Use net-misc/dhcpcd for getting an IP
I use KDE Network Manager gui (plasma-nm) to configure interfaces, which uses the underlying nmcli to configure network interfaces.
In the KDE network configuration (plasma-nm) IPV4 tab (IPV6 disabled here) there is an advanced options which opens a dialog that has options for send hostname (checked) and a DHCP hostname field populated with my machines hostname as found in /etc/hostname.
Network connection configuration can also be done via nmtui. Nmtui can be used to set hostname options. If someone is using dhcpcd or dhcpcd as a backend for NetworkManager, then those might be configured to set the hostname. For example:
https://wiki.gentoo.org/wiki/NetworkMan ... a_hostname
Code: Select all
Setting a hostname
If NetworkManager was built with the dhclient USE flag enabled a hostname can be set using the following command:
FILE /etc/dhcp/dhclient.conf
send host-name "customhostname";
With that in mind, It might be helpful to check for multiple conflicting DHCP hostname configurations on the system.
When using NetworkManager, systemd users should make sure that systemd-networkd service is disabled and not running as this can also interfere with NetworkManager and could cause conflicts with the DHCP hostname settings. At one time (it may still be the case), systemd-networkd was in the list of default systemd services. When following the gentoo installation handbook the command 'systemctl preset-all' would enable systemd-networkd service on new installations. For users that would later be installing and using NetworkManager, they would need to disable systemd-networkd. They may not realize that systemd-networkd conflicts with NetworkManager or that they had even originally enabled it when enabling the default selection of systemd's preset services.
In addition to systemd-networkd, it may be necessary to review the enabled systemd services to look for and disable any other network managers or DHCP servers which would conflict with NetworkManager. To see a list of services on systemd and their status, use:
Nmtui configuration tool does have an option to set the hostname as well:
https://networkmanager.dev/docs/api/latest/nmtui.html
Nmcli provides for several hostname configuration settings, specifically the dchp-hostname property (one could also choose to send a fully qualified domain name instead):
Code: Select all
ipv4.dhcp-hostname
If the "dhcp-send-hostname" property is TRUE, then the specified name will be sent to the DHCP server when acquiring a lease. This property and "dhcp-fqdn" are mutually exclusive and cannot be set at the same time.
https://networkmanager.dev/docs/api/lat ... nmcli.html
With all of that in mind, it might be helpful to check any of the NetworkManager connection-specific configuration files for any DHCP hostname conflicts. In my case, those files are found in /etc/NetworkManager/system-connections/ .
For further reading, an interesting and relatively recent breakdown of some of the changes in the default order of the hostname assignment in NetworkManager:
Code: Select all
A quick overview of NetworkManager 1.40 hostname assignment handling
Published: 16 Jul, 2024
https://networkmanager.dev/blog/address ... ager-1-40/