If you need to find out the name of your Ubuntu computer, this post shows you several ways to find it. We’ll also show you how to easily change the hostname. Ubuntu 17.x has a device name and hostname which appear to be different. The device name is displayed in the GUI and the hostname is displayed in the Terminal. I’ll show you how to change both.
Find your Ubuntu hostname
Your hostname can be found in several places. First of all, we’ll look at the Terminal window. To open a Terminal window, select Accessories | Terminal from the application menu. On newer versions of Ubuntu, such as Ubuntu 17.x, you need to click Actions and then enter terminal.
Your hostname appears after your username and the “@” symbol in the title bar of the Terminal window. In our case, our hostname is “ubuntu-virtual”. It also appears in the tooltip itself.
This may seem redundant since the hostname is already displayed in the title bar and in the prompt, but you can also enter the following command to view the hostname.
– / $ hostname
Change Ubuntu hostname
There is a hostname file in the / etc directory that contains your hostname. This used to be the only way to change the hostname. Fortunately, there is an easier way. The easiest way to change your Ubuntu hostname is to just go to settings.
Depending on your version, this is the gear icon in the upper right corner of the screen, or the gear icon in the new dock. If the gear icon is in the upper-right corner, click About This Computer.
If you needed to open “Settings”, scroll down to “Details” and click on it.
When you click on “Details”, you will automatically be taken to the “About” screen. You will see an editable text box titled “Device Name”. Just enter the new hostname you want and hit Enter.
It’s worth noting that this method will permanently change the hostname, meaning you can restart and the new name will remain.
Edit hostname and host files
Edit hostname and hosts files
Another way to change the hostname is to open a Terminal window and enter the following command:
sudo hostname new-name
This will change the hostname, but upon restart it will revert to what is in the / etc / hostname file. If you need to change it permanently, you can edit the hostname file I mentioned earlier. To do this, open a terminal and enter the following command:
sudo vi / etc / hostname
The file should contain nothing other than the hostname on the first line. In vi, you can enter insert mode by pressing the letter i. To delete characters, press the x key. You can also press the letter a to go into add mode. Note, to delete letters with x, you must first press ESC to exit insert or add mode.
After you change the name there, you will also need to change it elsewhere. Use the following command:
sudo vi / etc / hosts
Change the second line that starts with 127.0.0.1.
After you change it in both of these locations, you can restart and the new name will remain. It should be noted that the name of the device in the settings will still show something else. So there seems to be a difference between the device name and the hostname. I’m not sure what the difference is and why it doesn’t update on the About page, but that’s what worked for me. Enjoy!
–