·

·

Linux change hostname

To change the hostname in Linux, you can use the hostnamectl command. Here’s how:

  1. Open the Terminal.
  2. Check the current hostname by running the following command:
hostnamectl

This will display the current hostname, as well as other system information.

  1. Change the hostname by running the following command:
sudo hostnamectl set-hostname new-hostname

Replace “new-hostname” with the new hostname you want to set. Note that the new hostname must be a valid hostname, consisting of letters, digits, and hyphens.

  1. Update the /etc/hosts file by running the following command:
sudo nano /etc/hosts

This will open the hosts file in the Nano text editor. Replace the old hostname with the new hostname in the line that starts with “127.0.0.1”, so it looks like this:

127.0.0.1   new-hostname localhost

Save and close the file by pressing Ctrl+X, then Y, and then Enter.

  1. Log out and log back in to apply the changes.

Note that changing the hostname may affect certain network services and applications that rely on the hostname. You may need to restart the affected services or applications after changing the hostname.



Leave a Reply

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