How to Change Hostname for Ubuntu Machine ?

Recently, we wanted to change the hostname of our Ubuntu machine,

$ lsb_release -a

Lets, check now what is current hostname,

$ hostname
new-hostname

So, its set to “new-hostname”

Now, to change the hostname lets say “my-netbook”, user the command as,

$ hostnamectl set-hostname my-netbook

Now, open a new terminal and verify that its changed,

$ hostname
my-netbook

So, its now changed 🙂

In certain case, using sudo you might get an error like “unable to reolve host” to resolve this follow “How to Fix : sudo: unable to resolve host my_user: No such file or directory”

Leave a Comment