How to change the hostname in Ubuntu

In this article you will learn how to modify the computer name ( hostname ) in ubuntu starting from 14.10 release.

It ‘s not complicated to change it since we will be editing the hostname files.First open up the terminal and run the following command in order to know your current hostname :


Read: How to create a Sudo user on Ubuntu

To modify it, edit the file /etc/hostname first using your preferred editor :

sudo gedit /etc/hostname

Delete the hostname displayed and insert any name you like (we chose mac ). Finally save your file and exit.

Now you edit the file /etc/hosts :

sudo gedit /etc/hosts

Read: How to use sudo without having to enter a password in Ubuntu

And change the name (we changed it from ubuntu to mac) to what you chose above . Save and exit.

Now you need to reboot your system. You can then check again your hostname :

It shows the name you chose above.

If you like the content, we would appreciate your support by buying us a coffee. Thank you so much for your visit and support.


ziad nahdy

Ziad Nahdy, fan of open source and programming languages. He is a technical writer, blogger and Linux enthusiast. He loves to read and help others with their problems. He is addicted to open source software but he also loves other technology related subjects.

Leave a Reply