To change the hostname of a CentOS/RHEL 7 system, you can use the following commands:
# hostnamectl set-hostname newhostname
Replace “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/network
Update 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 network
You can verify the new hostname by running the hostnamectl
command:
# hostnamectl