How to immediately apply changes to the hostname in CentOS 7?

To enact hostname changes immediately, use the following command:

  1. Check the current hostname using the command hostnamectl.
  2. Use the command “hostnamectl set-hostname” to change the hostname of the host, specifying the new hostname: sudo hostnamectl set-hostname new hostname.
  3. Check the modified hostname again using the hostnamectl command to confirm the changes have been successful.
  4. 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.

bannerAds