How do I rename the RedHat7 hostname without a reboot? I am also trying to automate this task.

  • I tried the solution below and it just worked great on my Debian Jessie :). – ivanleoncz Nov 14 '18 at 23:10
[root@stephan ~]# echo stephan2 > /etc/hostname # this is the file that your system reads on boot, to determine the hostname
[root@stephan ~]# sed -i s/stephan/stephan2/g /etc/hosts # many networking headaches will ensue if this isn't updated
[root@stephan ~]# hostname -F /etc/hostname # reread the hostname file to update the systems hostname.

Your prompt will continue to display the old hostname until you log out of it and back in, or execute a new shell session.

[root@stephan ~]# logout
[stephan@stephan ~]$ sudo su -
Last login: Wed Sep 28 18:06:35 EDT 2016 on pts/0
[root@stephan2 ~]#
  • what is "s/stephan/stephan2/g"? Thanks. – tset Sep 29 '16 at 0:06
  • 'sed' is the stream text editor. It's a command that changes text in place, either from a stream of text you 'pipe' into it, or occurrences of that text in a file. en.wikipedia.org/wiki/Sed – Stephan Sep 29 '16 at 18:00

Use the following command to change the hostname on RHEL7:

hostnamectl set-hostname name

To view current hostnames:

hostnamectl status

Refer to the Red Hat Enterprise Linux Networking guide for further details.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.