hostname-mode=default and hostname set outside NM


using NetworkManager-1.20.0-5.el8_1.x86_64 on CentOS 8.1 I tried to figure out the hostname-mode semantics beyond what the manual says (I've got another thread for this but somehow unrelated to the following question).

In this post, I'd like to clarify this NetworkManager.conf(5) quote for default :

"If not present, the hostname will be updated to the last one set outside NetworkManager."

For what I saw when tracing, nm-policy reads the hostname-original and restores this hostname when the DHCP connection gets deactivated.

Looking at the source, it seems to match this part in nm-policy.c:update_system_hostname() :

if (!priv->default_ac4 && !priv->default_ac6) {
/* No best device; fall back to the last hostname set externally
                 * to NM or if there wasn't one, 'localhost.localdomain'
_set_hostname (self, priv->orig_hostname, "no default device");

Same kind of mechanism without default fallbacks for hostname-mode=dhcp

What's not clear to me is : what if the transient hostname is changed outside NetworkManager after hostname-original gets read at NM start ? Let's say someone issues hostname foobar (instead of hostnamctl --transient set-hostname foobar) while the DHCP connection is still up : would that become the new set-out-of-NM hostname wich would be restored when the connection is deactivated ?

Technically NM could notice it directly issuing gethostname(3) but my understanding is that it would rather rely on systemd-hostnamed/dbus for that. The latter seems to have in some cases some delay to catch up with transient hostanme.

Thanks for your help


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