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.
Important: You also need to edit the /etc/hosts file and apply the changes. Otherwise, you won't be able to use sudo after the reboot.
That's it.
Worked like a charm for me. THanks.
ReplyDeleteDon't forget the entry in the /etc/hosts file may still be the old name next to 127.0.0.1
ReplyDeletesweet man thanks, remember to edit the /etc/hosts like Gregor said as sudo quits working and you have to unlock your root account to fix it.
ReplyDeleteThanks, it works..
ReplyDeleteI just hosted my server because of this guide. The requirement of editing /etc/hosts needs to be in your article, not just the comments. Lesson learned, and chances are I had to rebuild anyway after the hostname change with everything else on the box, so no huge loss. Please update your article so others do not have to go though this. Thanks
ReplyDeleteIf you want learn how to change your hostname (computer name) on Ubuntu Server you can take a look at Change hostname (computer name) on Ubuntu Server (video tutorial).
ReplyDelete