How to set the hostname of CentOS using the command line?
To set the hostname of CentOS through the command line, you can follow these steps:
- Open the terminal or log in to the CentOS server console.
- Use the following command to check the current host name:
hostname
- Use the following command to permanently set the hostname, replacing “your-hostname” with the desired hostname:
sudo hostnamectl set-hostname your-hostname
- Use the following command to immediately apply the change to the hostname:
sudo hostname your-hostname
- Verify if the hostname has been changed using the following command:
hostname
- Reboot the system to ensure the hostname change has taken effect:
sudo reboot
By following the steps above, you can set the hostname of CentOS using the command line.