Ubuntu 18.04 LTS change hostname permanently

To change the hostname of an Ubuntu 18.04 LTS system permanently, you can use the following steps:

  1. Open a terminal and run the following command to edit the “/etc/hostname” file:
sudo nano /etc/hostname
  1. Replace the current hostname with the new hostname in the file and save the changes by pressing ctrl + x followed by y and then press Enter
  2. Next, edit the “/etc/hosts” file by running the following command:
sudo nano /etc/hosts
  1. Update the hostname in the file and make sure that the hostname is unique in the local network.
  2. Save the changes and exit the file by pressing ctrl + x followed by y and then press Enter
  3. Run the following command to apply the changes:
sudo hostname new-hostname
  1. 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)

Leave a Comment