Changing the computer (host) name in Ubuntu

You’d think this would be easy.  Using the GUI, just go to “System Settings” > “Details”.  See the box with my computer’s name (Device name) in it?


In theory, it seems like I should just be able to click on that and type a new name in.


Instead, for some unknown reason, I have to open up Terminal and perform this from the command line.  And, it requires modification of two different files!  Why?  I guess one of the continuing quirks of using Ubuntu.

Anyway, here’re the files that need to be edited and here’re the commands to do so:

1.  Edit the /etc/hostname file

$gksudo gedit /etc/hostname

Remember to use gksudo to open gedit. I discovered this not too long ago. Once the file opens, just replace the existing Device name with the new one. In my file, there was no other text; only the current Device name.

2. Edit the /etc/hosts file

$gksudo gedit /etc/hosts

Once this file opens, find your current Device name and replace it with the new one that you entered in Step 1 above.

So, that’s it, I guess. It certainly isn’t the most intuitive way to accomplish this, but I guess it’s the only way to accomplish the task.