How to Change Hostname on Ubuntu 20.04

To change the hostname on Ubuntu 20.04, you can use the hostnamectl command. Here are the steps to change the hostname on Ubuntu 20.04:

  1. Open a terminal window on your Ubuntu 20.04 system.
  2. Check the current hostname by running the following command:
hostnamectl
  1. To change the hostname, use the following command, replacing “new_hostname” with the desired hostname:
sudo hostnamectl set-hostname new_hostname
  1. Verify the new hostname by running the command from step 2 again.
  2. To make the change permanent across reboots, you will need to edit the hostname in the hostname file, open the file with:
sudo nano /etc/hostname
  1. Replace the old hostname with the new hostname, save and exit the file.
  2. You also have to update the hostname in the hosts file:
sudo nano /etc/hosts
  1. Change the hostname everywhere in the file, save and exit.
  2. Finally, reboot your system to apply the changes:
sudo reboot

Once the system is back up, the new hostname should be in effect. Keep in mind that changing the hostname might cause issues with any services or applications that are configured to use the old hostname.

Leave a Comment