Update Hostname on CentOS 7/8

Display the Current Hostname

  1. Enter one of the following commands
    $ hostname


    $ hostnamectl

Change the Hostname

  1. Edit /etc/hostname using nano or vi/vim text editor
    $ sudo vim /etc/hostname
  2. Delete the old hostname and set the new hostname
  3. Repeat the process with any instances of the old hostname in /etc/hosts
    $ sudo vim /etc/hosts
  4. Reboot the system for the changes to take effect

Change the Hostname without Rebooting

  1. Type the following to set the hostname
    $ sudo hostname new-hostname


    $ sudo hostnamectl set-hostname new-hostname
  2. Repeat the above steps to update /etc/hostname and /etc/hosts

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.