To change the hostname in Ubuntu 18.04 LTS permanently, you can use the following steps:
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.
Save and close the file.
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_hostnameSource:www.lautturi.com
Replace new_hostname
with the hostname you have set in step 1.
Save and close the file.
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.