Re: Hostname Management



On Fri, 2021-07-23 at 17:24 +0100, Mark Corbin wrote:
Hello

I'm trying to control a device hostname independently of
NetworkManager, 
but am unable to disable NetworkManager's hostname management. I'm
using 
NM version 1.28.2

I've added the following to the configuration file:

[main]
hostname-mode=none

that's right. This is documented in `man NetworkManager.conf`.


When NM starts at boot I see the following messages:

hostname: hostname: using hostnamed
hostname: hostname changed from (none) to "<my hostname>"

that's only informational. It doesn't mean that NetworkManager actively
changes the hostname of your system.


Using nmcli to set the hostname triggers a DBus call to set the static 
(which fails) and transient (which succeeds) hostnames:

`nmcli general hostname` sets the static hostname.

That is mostly unrelated to `[main].hostname-mode`, which is about the
transient hostname.

This comes from a time before hostnamectl. Today there is little reason
to call this. Just use hostnamectl to set the static hostname.

Setting the transient hostname on the other hand still makes sense and
(depending on your environment) is NetworkManager's job. This way you
can get the (transient) hostname from DHCP or via reverse DNS lookup.
But it doesn't seem that you want that (which is sensible. Just set a
static hostname instead).


Jul 23 16:11:03 OldHostname dbus-daemon[1368]: [system] Activating via 
systemd: service name='org.freedesktop.hostname1' 
unit='dbus-org.freedesktop.hostname1.service' requested by ':1.4'
(uid=0 
pid=1472 comm="/usr/sbin/NetworkManager --no-daemon ")
Jul 23 16:11:03 OldHostname audit: AUDIT1334 prog-id=35 op=LOAD
Jul 23 16:11:03 OldHostname audit: AUDIT1334 prog-id=36 op=LOAD
Jul 23 16:11:03 OldHostname kernel: audit: type=1334 
audit(1627056663.748:120): prog-id=35 op=LOAD
Jul 23 16:11:03 OldHostname kernel: audit: type=1334 
audit(1627056663.748:121): prog-id=36 op=LOAD
Jul 23 16:11:03 OldHostname dbus-daemon[1368]: [system] Successfully 
activated service 'org.freedesktop.hostname1'
Jul 23 16:11:03 NewHostname systemd-hostnamed[10804]: Failed to write
static host name: Device or resource busy
Jul 23 16:11:03 NewHostname NetworkManager[1472]: <warn> 
[1627056663.9942] hostname: could not set hostname: 
GDBus.Error:System.Error.EBUSY: Failed to set static hostname: Device
or 
resource busy
Jul 23 16:11:03 NewHostname NetworkManager[1472]: <info> 
[1627056663.9944] audit: op="hostname-save" arg="NewHostname" pid=10800
uid=0 result="fail" reason="Saving the hostname failed."

I was hoping that nmcli would return "set-hostname: hostname is 
unmanaged" when hostname-mode set to 'none'.

`nmcli general hostname` calls SetHostname on D-Bus, which ends up at
this code:

  
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/blob/888735838382cf45530914b34d383277ff4ddbe4/src/core/nm-hostname-manager.c#L330


I have two questions:
1) Can I configure NM so that it doesn't make any attempts to change 
either the static or transient device hostname?

- NM only sets the static hostname if you call the respective API.
Don't don't do that, if you don't want that.

- to avoid NM setting the transient hostname, hostname-mode=none would
work. Alternatively just configure a static hostname.

2) If I change the hostname externally from NM should the NM service
be 
restarted?

No. NM listens to signals from systemd-hostnamed or watches
/etc/hostname file. It would pick up the change automatically.



best,
Thomas



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]