Change HostName Permanently – Ubuntu

We can manually edit these files using a text editor like vim:

sudo vim /etc/hosts
sudo vim /etc/hostname

In /etc/hostname simply overwrite the existing hostname with a new one. In /etc/hosts

you will find the hostname on the line beginning 127.0.0.1 – overwrite only the hostname with the new one, and then reboot.

Editing /etc/hosts using nano