How to change the hostname on ubuntu server

Your hostname is a label that is assigned to your computer so that it can be identified.

There are only a couple of steps:

Step 1

Edit /etc/hosts:

$ sudo vi /etc/hosts

You dont have to use vi you can open it with any text editor. Here you should see your current hostname, change it to the one you want.

Step 2

Edit /etc/hostname:

$ sudo vi /etc/hostname

Here you should see not the hostname you just entered into /etc/hosts but the old one. Change it to your new one.

Step 3

Restart the hostname service:

$ sudo service hostname restart

or

$ sudo /etc/init.d/hostname restart