RHEL / Centos Linux 7: Change and Set Hostname Command
To change the hostname of a CentOS/RHEL 7 system, you can use the following commands:
# hostnamectl set-hostname newhostnameReplace "newhostname" with the desired hostname for your system.
In addition to changing the hostname, you may also need to edit the /etc/sysconfig/network file to set the hostname permanently:
# nano /etc/sysconfig/networkUpdate the line that starts with HOSTNAME= to include your new hostname. Save and close the file, then restart the network services for the changes to take effect:
# systemctl restart networkYou can verify the new hostname by running the hostnamectl command:
# hostnamectl
