logo
. . .

A Step-by-Step Guide on How to Change the Hostname in Ubuntu

Step 1: Check the Current Hostname

Before making any changes, it’s a good idea to check the current hostname. You can do this by entering the following command in the terminal:

#hostname

This will display the current hostname of your system.

Step 2: Edit the Hostname File

Next, open the /etc/hostname file using a text editor of your choice. For example, you can use nano:

#sudo nano /etc/hostname

Replace the existing hostname with the new one, save the file, and exit the text editor.

Step 3: Edit the Hosts File

Now, open the /etc/hosts file:

#sudo nano /etc/hosts

Locate the line with the old hostname and replace it with the new one. Save the file and exit.

Step 4: Apply the Changes

After editing the hostname and hosts files, apply the changes without restarting your system. Run the following command:

#sudo service hostname restart

Alternatively, you can reboot your system to ensure the changes take effect.

Step 5: Verify the Changes

Confirm that the new hostname is in place by running:

# hostname

Additionally, check the /etc/hostname and /etc/hosts files to ensure the changes are reflected.