To change the hostname of a Red Hat Enterprise Linux (RHEL) or CentOS Linux 7 system, you can use the hostnamectl
command.
Here are the steps to change the hostname of a RHEL or CentOS Linux 7 system:
hostnamectl set-hostname
command to set the new hostname. For example:sudo hostnamectl set-hostname newhostname
This will set the new hostname for the system.
/etc/hosts
file and update the localhost
entry with the new hostname. For example:127.0.0.1 localhost newhostname
This will ensure that the new hostname is resolved correctly on the system.
sudo systemctl restart network
The hostname of the system will now be changed to the new hostname.
It's always a good idea to carefully review the documentation and use the appropriate commands to change the hostname of a RHEL or CentOS Linux system. This will help ensure that the hostname is set correctly and that the system is properly configured.