If you need to know the name of your Ubuntu computer, this post shows you several ways to find it. We will will also show you how to easily change your host name. In Ubuntu 17.x, there is a device name and a host name, which seem to be different. The device name shows up in the GUI and the host name shows up in Terminal. I’ll show you how to change both.

Find Ubuntu Host Name

Your host name can be found in several places. The first place we will look is the Terminal window. To open the Terminal window, select Accessories | Terminal from the Applications menu. In newer versions of Ubuntu, like Ubuntu 17.x, you need to click on Activities and then type in terminal.

Table of Contents

    Opening the Terminal window

    Your host name displays after your username and the “@” symbol in the title bar of the Terminal window. In our case, our host name is “ubuntu-virtual.” It also displays in the prompt itself.

    It may seem redundant, as the host name already displays in the title bar and the prompt, but you can also enter the following command to view the host name.

    $ hostname

    Change Ubuntu Hostname

    There is a hostname file in the /etc directory that contains your hostname. Previously, it was the only way to change the host name. Luckily, there is a different way that is easier. The easiest way to change your Ubuntu hostname is to simply go to Settings.

    Depending on your version, it’s the gear icon at the top right of the screen or the gear icon in the new dock. If the gear icon is in the top-right corner, click on About this Computer.

    If you had to open Settings, scroll all the way down to where it says Details and click on that.

    When you click on Details, it should bring you to the About screen automatically. You will see an editable text box called Device name. Just type the new host name you would like and press Enter.

    It’s worth noting that this method will change the host name permanently, meaning you can restart and the new name will remain.

    Edit Hostname and Hosts Files

    Another way to change the host name is to open a Terminal window and type in the following command:

    sudo hostname new-name

    This will change the host name, but it will go back to whatever is in the /etc/hostname file after a restart. If you need to change it permanently, you can edit the hostname file I talked about earlier. To do that, open terminal and type in the following command:

    sudo vi /etc/hostname

    The file should have nothing but the hostname in the first line. In vi, you can go into Insert mode by pressing the letter i. To delete characters, you press the x key. You can also press the letter a to go to Append mode. Note that to delete letters using x, you have to press ESC first to get out of Insert or Append mode first.

    Once you change the name there, you also need to change it in one other location. Use the following command:

    sudo vi /etc/hosts

    Change the second line that starts with 127.0.0.1.

    Once you change it in both of these locations, you can restart and the new name will remain. It’s worth noting that the device name in Settings will still show something else. So there seems to be a difference between the device name and the host name. I’m not sure what the difference is and why it doesn’t update in the About page, but that’s how it worked for me. Enjoy!