I am currently running Fedora 35 in a VM. What I have installed is the “Minimal” and basic GNOME shell.
I am currently setting the machine’s hostname. It behaves normally when I set it to something random. But when I try to set the hostname to localhost using hostnamectl, I find that the setting gets overwritten by Fedora.
If I set the hostname to something out of “localhost”, everything looks normal.
[loctune@machine ~]$ hostnamectl hostname random
[loctune@random ~]$ hostnamectl status
Static hostname: random
Icon name: computer-vm
Chassis: vm
Machine ID: b34555ec4ef84a81abc435f647d006d4
Boot ID: 06a26791697547b483d72eece1d64316
Virtualization: microsoft
Operating System: Fedora Linux 35 (Thirty Five)
CPE OS Name: cpe:/o:fedoraproject:fedora:35
Kernel: Linux 5.16.5-200.fc35.x86_64
Architecture: x86-64
Hardware Vendor: Microsoft Corporation
Hardware Model: Virtual Machine
If I try to set it to localhost, the output looks like this:
[loctune@random ~]$ hostnamectl hostname localhost
[loctune@localhost ~]$ hostnamectl status
Static hostname: localhost
Transient hostname: fedora
Icon name: computer-vm
Chassis: vm
Machine ID: b34555ec4ef84a81abc435f647d006d4
Boot ID: 06a26791697547b483d72eece1d64316
Virtualization: microsoft
Operating System: Fedora Linux 35 (Thirty Five)
CPE OS Name: cpe:/o:fedoraproject:fedora:35
Kernel: Linux 5.16.5-200.fc35.x86_64
Architecture: x86-64
Hardware Vendor: Microsoft Corporation
Hardware Model: Virtual Machine
A transient hostname “fedora” kicks in immediately. At this time, the /etc/hosts, /etc/hostname, sysctl kernel.hostname, hostname -f all show “localhost” as expected as well as inside the terminal. However, fedora is shown in the gnome-terminal title as well as gnome-settings computer/device name, as the environment variable $HOSTNAME gets overwritten (need a refresh to show in echo).
[loctune@localhost ~]$ echo $HOSTNAME
fedora
Currently, I find no way to change this transient hostname. hostnamectl gives:
[loctune@localhost ~]$ hostnamectl hostname --transient localhost
Hint: static hostname is already set, so the specified transient hostname will not be used.
and the transient hostname fedora is not altered. Nor do I find a way to change this overwriting behavior. Settings in NetworkManager.conf with hostname-mode=none does not stop it from getting this fedora as expected, as likely this name does not come from DHCP. Even when I have no Internet connection at all, altering the hostname to localhost or localhost.localdomain still gives me this fedora immediately.
Oddly, this overwriting behavior is only found in Fedora. I tested a few other distros including RHEL 8.5 and 9 Beta, and a few Deb-based inside the same VM, and none of them provides/requires a transient hostname like Fedora and overwrites the $HOSTNAME when static is set to localhost. Thus I would infer that this is reasoned from some local settings in Fedora.
Do someone have experience with this behavior, and have experience dealing with this issue?
Thanks.
Loc
EDIT:
When I updated my Arch in VM, it now behaves similar to Fedora. When you do systemctl it also gets a transient hostname “archlinux” and write that to gnome-settings computer/device name. The difference is that it does not overwrite $HOSTNAME, so echo gives out normal output.
I wonder whether this is due to any change in GNOME, NetworkManager or other parts of the system.