How to immediately apply changes to the hostname in CentOS 7?
To enact hostname changes immediately, use the following command:
- Check the current hostname using the command hostnamectl.
- Use the command “hostnamectl set-hostname” to change the hostname of the host, specifying the new hostname: sudo hostnamectl set-hostname new hostname.
- Check the modified hostname again using the hostnamectl command to confirm the changes have been successful.
- Restart the systemd-hostnamed service immediately to apply the hostname by running the command sudo systemctl restart systemd-hostnamed.
After completing the above steps, the new hostname will take effect immediately. You can verify the changes by running the hostnamectl command again.