How do I rename the RedHat7 hostname without a reboot? I am also trying to automate this task.
[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 ~]#
Use the following command to change the hostname on RHEL7:
hostnamectl set-hostname name
To view current hostnames:
Refer to the Red Hat Enterprise Linux Networking guide for further details.