How to change hostname in ubuntu 20.04?


by lonzo , in category: General Help , 2 years ago

How to change hostname in ubuntu 20.04?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by viola_gleichner , a year 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.


by viola_gleichner , 7 months ago


This command will display the current hostname of the system.