Find and Change Your Hostname in Ubuntu
In both the GUI and Terminal
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, selectAccessories | Terminalfrom theApplicationsmenu. In newer versions of Ubuntu, like Ubuntu 17.x, you need to click onActivitiesand then type interminal.
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.
Change Ubuntu Hostname
There is ahostnamefile in the/etcdirectory 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 toSettings.
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 onAbout this Computer.
If you had to open Settings, scroll all the way down to where it saysDetailsand click on that.
When you click on Details, it should bring you to the About screen automatically. You will see an editable text box calledDevice name. Just type the new host name you would like and pressEnter.
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:
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:
The file should have nothing but the hostname in the first line. In vi, you can go intoInsertmode by pressing the letter i. To delete characters, you press the x key. You can also press the letter a to go toAppendmode. 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:
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!
Founder of Help Desk Geek and managing editor. He began blogging in 2007 and quit his job in 2010 to blog full-time. He has over 15 years of industry experience in IT and holds several technical certifications.Read Aseem’s Full Bio
Welcome to Help Desk Geek- a blog full of tech tips from trusted tech experts. We have thousands of articles and guides to help you troubleshoot any issue. Our articles have been read over 150 million times since we launched in 2008.
HomeAbout UsEditorial StandardsContact UsTerms of Use
Copyright © 2008-2024 Help Desk Geek.com, LLC All Rights Reserved