1. Change hostname by editing hostname and host system files
If you want to change your computer name on Ubuntu Linux, the procedure is as follows:
1. Open the terminal and type the following command to change /etc/hostname file, using nano or vi text editor:
sudo nano /etc/hostname
In that file, you'll see your current hostname, so remove the old name and configure a the new name.
2. Then, edit the /etc/hosts file:
sudo nano /etc/hosts
Replace any occurrence of the current computer name with your new one.
3. Reboot the system to changes take effect if you want to reboot through the terminal, type the following command:
4. After you reboot, you can see your new hostname in the terminal prompt, and if you want to check it explicitly, you can type the hostname command in your terminal, and you'll see your machine name as output.
2. Change hostname on Ubuntu Linux using hostnamectl
1. If you don't want to manually edit hostname and hosts files, you can use hostnamectl command which is available on Sysemd based Linux distributions.
hostnamectl set-hostname my-new-hostname
2. Then, you can check your current hostname with the following command: