How to change hostname in ubuntu 20.04?


by lonzo , in category: General Help , a year ago

How to change hostname in ubuntu 20.04?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by viola_gleichner , 9 months ago


To change the hostname in Ubuntu 20.04, follow these steps:

  1. Open a terminal window.
  2. Use the hostnamectl command to set the hostname. For example, to set the hostname to "new-hostname", use the following command:
sudo hostnamectl set-hostname new-hostname

  1. Edit the /etc/hosts file to reflect the new hostname. Open the file using your preferred text editor, such as nano or vi.
sudo nano /etc/hosts

  1. Locate the line that begins with and replace the hostname after the with the new hostname. For example:
1 new-hostname

  1. Save the changes to the /etc/hosts file and exit the text editor.
  2. Reboot the system for the changes to take effect.
sudo reboot

After the system reboots, the hostname will be changed to the new value. You can verify the new hostname by running the hostname command.