If you’ve changed your mind about your Linux hostname or you’ve set to wrong hostname, here is how to fix it.
Firstly, I’ve tried the following command:
$sudo hostname mybrandnewname
But this will revert back to prior hostname whenever the machine reboots. So how can you change it permanently? First you’ll need to edit /etc/hostname file
$sudo vi /etc/hostname Then delete the old name and type whatevername you desire
It is also advisable to change new hostname in /etc/hosts file
Source : UbuntuManual