How to permanently change hostname in Fedora 21
I’ve heard that changing the hostname in new versions of fedora is done with the hostnamectl
command. In addition, I recently (and successfully) changed my hostname on Arch Linux with this method. However, when running:
[[email protected] ~]# hostnamectl set-hostname --static paragon.localdomain
[[email protected] ~]# hostnamectl set-hostname --transient paragon.localdomain
[[email protected] ~]# hostnamectl set-hostname --pretty paragon.localdomain
The changes are not preserved after a reboot (contrary to many people’s claims that it does). What is wrong?
- I really don’t want to edit
/etc/hostname
manually.
I should also note that this is a completely stock fedora. I haven’t even gotten around to installing my core apps yet.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
The command to set the hostname is definitely, hostnamectl
.
root ~ # hostnamectl set-hostname --static "YOUR-HOSTNAME-HERE"
Here’s an additional source that describes this functionality a bit more, titled: Correctly setting the hostname – Fedora 20 on Amazon EC2.
Additionally the man page for hostnamectl
:
HOSTNAMECTL(1) hostnamectl HOSTNAMECTL(1) NAME hostnamectl - Control the system hostname SYNOPSIS hostnamectl [OPTIONS...] {COMMAND} DESCRIPTION hostnamectl may be used to query and change the system hostname and related settings. This tool distinguishes three different hostnames: the high-level "pretty" hostname which might include all kinds of special characters (e.g. "Lennart's Laptop"), the static hostname which is used to initialize the kernel hostname at boot (e.g. "lennarts-laptop"), and the transient hostname which is a default received from network configuration. If a static hostname is set, and is valid (something other than localhost), then the transient hostname is not used. Note that the pretty hostname has little restrictions on the characters used, while the static and transient hostnames are limited to the usually accepted characters of Internet domain names. The static hostname is stored in /etc/hostname, see hostname(5) for more information. The pretty hostname, chassis type, and icon name are stored in /etc/machine-info, see machine-info(5). Use systemd-firstboot(1) to initialize the system host name for mounted (but not booted) system images.
There is a bug in Fedora 21 where SELinux prevents hostnamectl access, found here, titled: Bug 1133368 – SELinux is preventing systemd-hostnam from ‘unlink’ accesses on the file hostname.
This bug seems to be related. There’s an issue with the SELinux contexts not being applied properly to the file /etc/hostname
upon installation. This manifests in the tool hostnamectl
not being able to manipulate the file /etc/hostname
. That same thread offered this workaround:
$sudo restorecon -v /etc/hostname
NOTE: That patches were applied to Anaconda (the installation tool) so that this issue should go away in the future for new users.
Method 2
The likely cause for this is your dhcp client. If you’re using dhcpcd, which is common, the solution is to add the following line to /etc/dhcpcd.conf
:
nohook hostname
This prevents dhcpcd from calling out to the script which changes your system hostname.
By default, dhcpcd runs all the hooks present /lib/dhcpcd/dhcpcd-run-hooks
(the path may differ on your system). Using nohook
disables specific ones.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0