To change the hostname in Ubuntu 20.04, follow these steps:
- Open a terminal window.
- 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
- Edit the /etc/hosts file to reflect the new hostname. Open the file using your preferred text editor, such as nano or vi.
- 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:
- Save the changes to the /etc/hosts file and exit the text editor.
- Reboot the system for the changes to take effect.
After the system reboots, the hostname will be changed to the new value. You can verify the new hostname by running the