How to change hostname in ubuntu 20.04?

Member

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

@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


by viola_gleichner , 5 months ago

@lonzo 

This command will display the current hostname of the system.