How to set your hostname the hard way

Story: Commands to Configure hostname on CentOS 7 and RHEL 7Total Replies: 5
Author Content
kikinovak

Mar 02, 2016
1:15 AM EDT
On my Slackware boxes, I just put the hostname in /etc/HOSTNAME and /etc/hosts. No 'hostnamectl' nonsense here.
penguinist

Mar 02, 2016
10:06 AM EDT
One more reason that I'm happy to keep my servers on CentOS 6, no hostnamectl nonsense there either.

jdixon

Mar 02, 2016
12:46 PM EDT
> I just put the hostname in /etc/HOSTNAME and /etc/hosts.

Does that change the current name, or does it only take effect when the machine is rebooted? I was under the impression you had to use the hostname command to change the current name. But I've never had to change the hostname on a running machine, so I'm not certain.
dotmatrix

Mar 02, 2016
12:56 PM EDT
@jdixon:

You are correct.

$man hostname

/etc/hostname Historically this file was supposed to only contain the hostname and not the full canonical FQDN. Nowadays most software is able to cope with a full FQDN here. This file is read at boot time by the system initialization scripts to set the hostname.
nmset

Mar 02, 2016
1:39 PM EDT
I just used hostnamectl to change that name 2 days ago and did not reboot. No problem until now. That doesn't seem a nonsense utility. Is it because it's a systemd tool ?
jdixon

Mar 02, 2016
2:23 PM EDT
> just used hostnamectl to change that name 2 days ago and did not reboot.

You don't need to reboot if you use the hostname command either. It just that (for Slackware) if you only change /etc/HOSTNAME, it's only read on a reboot.

Posting in this forum is limited to members of the group: [ForumMods, SITEADMINS, MEMBERS.]

Becoming a member of LXer is easy and free. Join Us!