Changing the hostname of your Ubuntu/Linux server is as simple as typing: hostname thenewname at the console, right? Wrong.
To change the hostname, login to the server, either at the console or through SSH and, with root privileges, launch an editor against the file /etc/hostname. I’m using nano:
nmino@ubuntu-vm:~$ sudo nano /etc/hostname
[sudo] password for nmino:
Now change the value for your server’s hostname. If you’re using nano as your editor simply hit ctrl-x to exit and hit enter when prompted to save the changes.
Now let’s edit /etc/hosts:
nmino@ubuntu-vm:~$ sudo nano /etc/hosts
[sudo] password for nmino:
Change the value for your server’s hostname and do a ctrl-x to exit and hit enter to confirm saving the changes.
Now do a reboot:
nmino@ubuntu-vm:~$ sudo shutdown -r 0
Your machine will reboot with the new hostname.