Cannot set static hostname

Hello everyone, I met a strange issue with f40. When I plug in my ethernet cable, the hostname on my machine changed. I just want my hostname stay as ‘fedora’, so I follow this official instruction (Changing Hostname :: Fedora Docs) to change my static hostname, However, I get this error.

Anybody has the same issue?
image

Check the output:

ls -l -d -Z /etc /etc/hostname
awk -e '$2=="/"||$2=="/etc"' /etc/mtab
1 Like

Thanks, I get this in return

[nathan36@MiWiFi-RC01-srv ~]$ ls -l -d -Z /etc /etc/hostname
drwxr-xr-x. 1 root root system_u:object_r:etc_t:s0     4940 Jun 11 23:55 /etc
-rw-r--r--. 1 root root unconfined_u:object_r:etc_t:s0    0 Jun 11 23:27 /etc/hostname
[nathan36@MiWiFi-RC01-srv ~]$ awk -e '$2=="/"||$2=="/etc"' /etc/mtab
/dev/nvme0n1p3 / btrfs rw,seclabel,relatime,compress=zstd:1,ssd,discard=async,space_cache=v2,subvolid=256,subvol=/root 0 0

Ah, that might be it then. Here’s the context it should have:

-rw-r--r--. 1 root root system_u:object_r:hostname_etc_t:s0 6 Mar 29  2021 /etc/hostname

Try sudo restorecon -v /etc/hostname and then try your original hostnamectl command again.

2 Likes

Thank you so much, you are life saver. This do solve my issue! :grin:

Cheers!

2 Likes