Ubuntu 18.04 LTS change hostname permanently

Ubuntu 18.04 LTS change hostname permanently

To change the hostname in Ubuntu 18.04 LTS permanently, you can use the following steps:

  1. Edit the /etc/hostname file as the root user and change the hostname to the desired value. The hostname should be a single word without any spaces or special characters.

  2. Save and close the file.

  3. Edit the /etc/hosts file and update the entry for the localhost to reflect the new hostname. The entry should look like this:

127.0.0.1   localhost new_hostname
‮‬Source:www.lautturi.com

Replace new_hostname with the hostname you have set in step 1.

  1. Save and close the file.

  2. Reboot the system for the changes to take effect.

Alternatively, you can also use the hostnamectl command to set the hostname. To do this, run the following command as the root user:

hostnamectl set-hostname new_hostname

Replace new_hostname with the desired hostname. This command will update the /etc/hostname and /etc/hosts files for you.

Note that changing the hostname may affect some applications and services that rely on the hostname to function properly. It is recommended to test the system after changing the hostname to ensure that everything is working as expected.

Created Time:2017-10-30 14:27:24  Author:lautturi