Hello Linux Geeksters. In this quick guide I will show you how to easily change the hostname on your Ubuntu, Linux Mint, Debian or Elementary OS system, without having to reboot your system.
First, we have to temporary change of hostname:
$ sudo hostname NewHostname
To apply the changes, we reload the shell (if you are using a different shell, type its name in the terminal):
$ bash
Now, let’s make this change persistent. We have to change the old hostname with the new one, in both the /etc/hostname and /etc/hosts files (the two sed oneliners will replace the old hostname with the new one, in the needed files):
$ sudo sed -i 's/OldHostname/NewHostname/g' /etc/hostname
$ sudo sed -i 's/OldHostname/NewHostname/g' /etc/hosts
In the below screenshot, I have replaced the hostname ubuntu with the hostname trusty (the grep commands in the screenshot are just to display the changes, before and after the sed one-liners)
Leave a Reply