Change the Hostname in Linux

There are many reasons why you might want to change the host name of your Linux system. Unfortunately, changing your hostname isn't exactly an intuitive process. But don't worry, we'll show you how to change your computer's hostname in less than a minute with just a few clicks and commands.

Although this guide uses Ubuntu to demonstrate the steps required to change the hostname, the commands should work on other Linux distributions as well.

What is a hostname?

All computers connected to a network have an IP address and a host name. The host name is the name used to identify a computer on a network in "human readable" form. Without the host name, when you were trying to find a computer on a network, you would only see numbers or IP addresses like

While IP addresses are a great way for computers to identify each other, they don't really help identify specific computers. Suppose you want to set up a shared network folder on your Ubuntu system. If someone else wants to access this folder, it will be much easier for them to find it if they see your computer on the network as a “Larry laptop” rather than “”.


A common reason for switching hostnames is to avoid duplicate names on the same network. Ubuntu, for example, sets the host name of all new installations to “ubuntu” by default. If you have more than one computer on your home network and you want them all to run Ubuntu Linux, you'll need to change the default hostnames to avoid problems.

How to change the host name via the system settings

The easiest way for most people to change the hostname on a Linux machine is to just go into System Preferences and click Above. The current host name of your computer appears as the first item in the list under Device name, or similar labels on other distributions.

It's not immediately obvious, but you can click the button Device name Item and a dialog box will appear allowing you to rename your device. Just enter the name you want in the dialog and then click on Rename.

The new host name will be set permanently and your computer will identify itself in your network with the new name.

Change the host name using the Linux terminal

The options that appear in your system preferences depend on the desktop environment you are using. The process described above works with the standard Ubuntu GNOME desktop. However, if you have changed your desktop environment or your window manager, you may not be able to change the hostname in the system settings.

In that case, you can change your hostname by opening a terminal window and typing a simple command.

the hostnamectl You can use this command to view and change the host name on most other Linux distributions. Just open a terminal window and enter the following command to see your current hostname along with some related details:



To change the host name, enter the following command and replace new-hostname with the name you want to use:

hostnamectl set-hostname new-hostname

To verify that the new name has been set, type hostnamectl again and you will see the updated information.

Again, the command line method of changing the Linux hostname should work on almost all modern Linux distributions, not just Ubuntu.

Learn more about how Linux networks work

Now that you've successfully set your computer's hostname, it's time to dip your toes into networking with Linux. If you have other network problems with your system (or even just curious about them), the ss command in Linux will help you troubleshoot the errors.

How to monitor network connections on Linux with ss

If you suspect a network problem on your Linux system, the ss command can be used to track and fix it.

Continue reading

About the author

JT McGinty
(6 articles published)

JT is a technology industry veteran with over 25 years of experience. From technical support and programming to system administration, he did everything. He especially enjoys teaching new users the freedom and power of Linux.

By JT McGinty

Subscribe to our newsletter

Subscribe to our newsletter for tech tips, reviews, free e-books, and exclusive offers!

Click here to subscribe

Leave a Reply

Your email address will not be published. Required fields are marked *