Advanced

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
12:15 AM EST
On my Slackware boxes, I just put the hostname in /etc/HOSTNAME and /etc/hosts. No 'hostnamectl' nonsense here.
penguinist

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

jdixon

Mar 02, 2016
11:46 AM EST
> 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
11:56 AM EST
@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
12:39 PM EST
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
1:23 PM EST
> 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.

Post a reply to this thread:

A free account is needed to post. Write your comment here first: your text is kept in this browser while you sign up or log in, and is waiting for you when you come back.

Your message:
|||||
10
Markdown: **bold**, *italic*, [text](https://link), - lists, > quotes, $x^2$ for math. Formatting help

Sign up and post (it is free)  or  Log in and post