How to change hostname in Ubuntu server

Change a hostname in Ubuntu server is very easy. From the command line terminal, type hostname newname. View the new hostname with hostname command. See the step by step example on how to change Ubuntu server hostname below:



1) View current hostname:



luzar@hitam:~$ hostname
hitam
luzar@hitam:~$


2) Change hostname and view latest hostname:



luzar@hitam:~$ sudo hostname ubuntu
luzar@hitam:~$ hostname
ubuntu
luzar@hitam:~$


See, that's how easy it is. Heh, don't fall for it. That doesn't change anything. The hostname is still the same as you can see at the prompt. Even reboot won't change anything. The exact method to change the hostname permanently is by editing /etc/hostname file. Here is the step:



1) Open /etc/hostname with your favorite text editor:



luzar@hitam:~$ sudo vim /etc/hostname
[sudo] password for luzar:


Here the vim /etc/hostname screenshot:





Now you can change hostname and save. The changed is permanent even after you reboot your system.