To change the hostname of an Ubuntu 18.04 LTS system permanently, you can use the following steps:
- Open a terminal and run the following command to edit the “/etc/hostname” file:
sudo nano /etc/hostname
- Replace the current hostname with the new hostname in the file and save the changes by pressing
ctrl + x
followed byy
and then pressEnter
- Next, edit the “/etc/hosts” file by running the following command:
sudo nano /etc/hosts
- Update the hostname in the file and make sure that the hostname is unique in the local network.
- Save the changes and exit the file by pressing
ctrl + x
followed byy
and then pressEnter
- Run the following command to apply the changes:
sudo hostname new-hostname
- Finally, reboot the system for the changes to take effect:
sudo reboot
After the reboot, you can verify the new hostname by using the hostname
command.
Note: The hostname should be in lowercase letters and numbers only, and it should not contain any special characters or spaces. It is also a good practice to check the DNS resolution after changing the hostname, to make sure the hostname is resolving to the correct IP address.
(Diazepam)