Ubuntu 20.04 LTS change hostname permanently
To change the hostname of an Ubuntu 20.04 LTS system permanently, you can use the hostnamectl command. Here are the steps to change the hostname:
- Open a terminal window and run the command
hostnamectl set-hostname new-hostnamereplacing "new-hostname" with the desired hostname. - Verify the new hostname by running the command
hostnamectl. - To make the change permanent, you will need to edit the
/etc/hostnamefile. Use your preferred text editor to open this file and replace the current hostname with the new one. - Also, you should check and edit the
/etc/hostsfile, this file should contain the IP address of your host and the new hostname. - After making the changes, save the file and close the text editor.
- Finally, reboot the system for the changes to take effect.
Also, it's always a good idea to have a backup of the files you will be editing and to take note of the original contents of the files, in case you need to revert the changes.
