So for whatever reason you need to change the hostname of your GNU Linux machine. For me this is usually because I am playing around with a virtual machine. I have automated the setup for a number machine installations. Once I have it running and configured I may want to keep, so changing it’s name is a nice thing to do.
Check your hostname is set to something and no errors are returned. The commands below will return the host name with and without the domain.
uname -a
uname -n
hostname -a
hostname -f
hostnamectl status
From Fedora 18 onwards and in Ubuntu at some point in the past, we have a new command to change the hostname, ‘hostnamectl’. Take a look at the man page it is only short š
More changes that are a retrograde step in usefulness.
The new command does not work correctly in Fedora 18. When trying to set all the names, as per the man page, the static names has all the fullstops removed. So very Windows! :-(
So now to change the name you have to run hostnamectl three commands with different options.
sudo hostnamectl set-hostname --pretty new-hostname
sudo hostnamectl set-hostname --transient new-hostname
sudo hostnamectl set-hostname --static new-hostname
Once the machine has rebooted use check that the new names are all set correctly, by using any of the commands above to see the static name or hostnamectl status to check all went well.
sudo hostnamectl status
uname -a
uname -n
hostname -a
hostname -f
There you go all done!
great, this command is applicable on almost all linux distributions
[added when I moved over to WordPress]
Thanks for the update, Iād never tried it with Ubuntu. I have tweaked the post.
Exactly what I was looking for. Thanks for the updates!
Great… So unsuccessful searches… Works perfectly with Fedora 20. Thank yo very much