How to change hostname in ubuntu 20.04?

Member

by lonzo , in category: General Help , 7 months ago

How to change hostname in ubuntu 20.04?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by viola_gleichner , a month ago

@lonzo 

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:
1
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.
1
sudo nano /etc/hosts


  1. Locate the line that begins with 127.0.1.1 and replace the hostname after the 127.0.1.1 with the new hostname. For example:
1
127.0.1.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.
1
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.

1
hostname