Bug 1356188

Summary: /etc/hostname change no longer takes effect immediately
Product: Red Hat Enterprise Linux 7 Reporter: Scott Poore <spoore>
Component: NetworkManagerAssignee: Beniamino Galvani <bgalvani>
Status: CLOSED NOTABUG QA Contact: Desktop QE <desktop-qa-list>
Severity: high Docs Contact:
Priority: high    
Version: 7.3CC: atragler, bgalvani, lrintel, mleitner, pkis, rkhan, sukulkar, systemd-maint-list, thaller
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-07-13 20:25:14 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Scott Poore 2016-07-13 15:29:34 UTC
Description of problem:

In RHEL7.2 and earlier, it seems as if updating /etc/hostname changed the hostname immediately.  Now it does not.  I have to either run hostname or hostnamectl command.

Is this a documented change in behavior?  Or was this maybe a fix of a bug in the old version? 

Example of what I'm seeing in additional info.

Version-Release number of selected component (if applicable):
systemd-219-23.el7.x86_64

How reproducible:
always as far as I can tell.

Steps to Reproduce:
1.  echo "<new hostname>" > /etc/hostname
2.  hostname

Actual results:
shows same hostname

Expected results:
used to show new/changed hostname

Additional info:

------------ [ rhel7.2 ] -----------------------

rhel_7.2_vm # hostname
vm3.example.com
rhel_7.2_vm # cat /etc/hostname
vm3.example.com
rhel_7.2_vm # echo newhostname > /etc/hostname
rhel_7.2_vm # hostname
newhostname
rhel_7.2_vm # rpm -q systemd
systemd-219-19.el7.x86_64

------------ [ rhel7.3 ] -----------------------
rhel_7.3_vm # hostname
rhel7-3.example.com
rhel_7.3_vm # cat /etc/hostname
rhel7-3.example.com
rhel_7.3_vm # echo newhostname > /etc/hostname
rhel_7.3_vm # hostname
rhel7-3.example.com
rhel_7.3_vm # sleep 60
rhel_7.3_vm # hostname
rhel7-3.example.com
rhel_7.3_vm # hostnamectl
   Static hostname: newhostname
Transient hostname: rhel7-3.example.com
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 71a559c395354fe6977d702cba94da9d
           Boot ID: fcb10e5ea4d34b17ae04c942c23f7ab6
    Virtualization: kvm
  Operating System: Red Hat Enterprise Linux Server 7.3 Beta (Maipo)
       CPE OS Name: cpe:/o:redhat:enterprise_linux:7.3:beta:server
            Kernel: Linux 3.10.0-467.el7.x86_64
      Architecture: x86-64
rhel_7.3_vm # hostname
newhostname
rhel_7.3_vm # hostnamectl
   Static hostname: newhostname
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 71a559c395354fe6977d702cba94da9d
           Boot ID: fcb10e5ea4d34b17ae04c942c23f7ab6
    Virtualization: kvm
  Operating System: Red Hat Enterprise Linux Server 7.3 Beta (Maipo)
       CPE OS Name: cpe:/o:redhat:enterprise_linux:7.3:beta:server
            Kernel: Linux 3.10.0-467.el7.x86_64
      Architecture: x86-64

Comment 2 Lukáš Nykrýn 2016-07-14 06:58:00 UTC
From systemd point of view this is a configuration file which tells what hostname should be set during boot.
There must be something else that watches it and change the hostname in kernel and my suspect is Network Manager:

[root@old ~]# hostname
old
[root@old ~]# echo myold > /etc/hostname 
[root@old ~]# hostname
old
[root@old ~]# systemctl start NetworkManager
[root@old ~]# hostname
myold
[root@old ~]# echo old > /etc/hostname 
[root@old ~]# hostname
old

Comment 3 Lukáš Nykrýn 2016-07-14 07:03:50 UTC
čec 14 08:33:36 old NetworkManager[955]: <info>  Setting system hostname to 'myold' (from system configuration)
čec 14 08:33:47 old NetworkManager[955]: <info>  Setting system hostname to 'old' (from system configuration)
čec 14 08:33:57 old NetworkManager[955]: <info>  Setting system hostname to 'myold' (from system configuration)
čec 14 08:34:09 old NetworkManager[955]: <info>  Setting system hostname to 'old' (from system configuration)
čec 14 08:35:07 old NetworkManager[955]: <info>  Setting system hostname to 'myold' (from system configuration)
čec 14 08:35:16 old NetworkManager[955]: <info>  Setting system hostname to 'old' (from system configuration)
čec 14 08:50:12 myold NetworkManager[955]: <info>  Setting system hostname to 'myold' (from system configuration)
čec 14 08:50:13 myold NetworkManager[955]: <info>  Setting system hostname to 'old' (from system configuration)

Comment 4 Scott Poore 2016-07-14 18:27:32 UTC
FYI, from the hosts I'm testing on, I see these versions:

-------------- rhel7.3 ---------------------

NetworkManager-1.4.0-0.3.git20160621.072358da.el7.x86_64

-------------- rhel7.2 ---------------------

NetworkManager-1.0.6-27.el7.x86_64

I do see NetworkManager running on both.

Comment 5 Beniamino Galvani 2016-07-18 09:43:54 UTC
AFAIK all the RHEL documentation suggests to use hostnamectl or
nmcli/nmtui to change the system hostname, and writing /etc/hostname
directly to do so only worked in RHEL 7.2 because we used to monitor
changes to the file to detect when hostnamectl updated the hostname;
but in this way we also caught manual changes to the file.

Now we monitor hostnamectl properties on D-Bus to detect a change of
the hostname and thus writing the file doesn't have effect on the
system hostname.

In my opinion this is correct as a change to the file should not
reconfigure automatically the system. It's also consistent with
hostnamed/hostnamectl (which doesn't pick up changes to the file).
All changes should go through either hostnamed or nmcli/nmtui.

Comment 6 Scott Poore 2016-07-18 12:40:02 UTC
Ok, that explains the change in behavior.  Should this be documented somewhere in 7.3 release notes or one of the guides?

Thanks,
Scott

Comment 7 Lukáš Nykrýn 2016-07-26 11:32:11 UTC
*** Bug 1359222 has been marked as a duplicate of this bug. ***

Comment 8 Beniamino Galvani 2017-07-13 20:25:14 UTC
This was documented in RHEL 7.3 Release Notes:

https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/7.3_Release_Notes/new_features_networking.html

and in the Networking Guide.