Skip to Content

3 ways to change hostname in Ubuntu Linux

Recently we got some questions from our readers.

  1. How can I change the hostname of my Ubuntu Linux system?
  2. What are the implications of changing the hostname?
  3. What should I consider when deciding on a new hostname?
  4. Are there any risks associated with changing the hostname of my Ubuntu Linux system?
  5. Is it possible to change the hostname back to its original setting if I don’t like the new one?

In this article, I will explain how to change the hostname in Ubuntu Linux in a few different ways.

Related: How to check hostname in Ubuntu

understanding hostname in Ubuntu

Before I jump into the question, it is necessary for you to know the hostname.

The hostname is a label that is used to identify a device connected to a network.

For example, if you have a company network with multiple computers and devices connected, it’s important to assign each device its own unique hostname.

This helps differentiate between the different devices on the network so that applications can easily connect to them without having to remember their IP address.

Additionally, if you need remote access to your devices, assigning a hostname can make it easier to connect.

what is the risk to change the hostname in Ubuntu ?

Before you go ahead and change your hostname, it’s important to understand the risks associated with making such a change.

One of the main issues is that all services running on the system will need to be restarted in order for them to recognize the new name. Additionally, any applications that were connecting to services running on this machine may be affected.

Another risk is that the hostname may conflict with an existing name in the network. This can cause various issues and it’s important to make sure that the new hostname doesn’t conflict with any other names in the same network.

I worked in an Oracle RAC environment and the importance of hostname was crucial. In this environment, each node had a unique hostname that was used by Oracle to identify the nodes and manage communication between them.

It was important for us to ensure that the hostnames for each node were consistent, as changing a node’s hostname could lead to errors and instability in the network.

change hostname in Ubuntu with hostnamectl command

The best way to change the hostname of your Ubuntu system is to open up a terminal and type in the following command:

sudo hostnamectl set-hostname “new_hostname”

This will change the hostname of your system to what you specified in place of “new_hostname”.

The hostnamectl command is a utility used to manipulate the system’s hostname. You can use this command to view, set or even change the hostname of your Ubuntu machine.

Do you know what is behind the scene?

This command will permanently store a static hostname in the /etc/hostname file.

Using the hostnamectl command to change your hostname has several advantages.

It allows you to quickly and easily change the hostname without having to edit any configuration files manually.

change hostname in Ubuntu with /etc/hostname file

The last method for changing your hostname is to edit the /etc/hostname file directly. This is a bit more complicated than using any of the other methods, so it’s recommended that you use one of the above methods instead if possible.

To edit this file, open up a terminal window and type in “sudo nano /etc/hostname”. Then, change the value of the hostname to whatever you want your new hostname to be and save the file.

Once you’ve made your changes, it’s important to restart the system for them to take effect. You can do this by typing in “sudo reboot” at the command line, or you can use the graphical user interface by clicking on the “Restart…” button in the System Settings menu.

After your system has restarted, you should be able to verify that your hostname has been successfully changed by typing in “hostname” at the command line. If everything was successful, you should see the new hostname printed out at the command prompt.

change hostname in Ubuntu Linux with GUI

Another way to change your hostname in Ubuntu Linux is through the graphical user interface (GUI). To do this, first open up the System Settings menu and click on “Details”.

Then, select the “System” tab and at the bottom you should see a field labeled “Hostname”. Simply enter your new hostname in this field and press the “Apply” button at the bottom of the window.


In conclusion, it is important to consider any potential risks before making changes to your hostname in Ubuntu Linux. However, with the right tools and knowledge, you should be able to easily change your hostname without any trouble.

The simplest way is to use the hostnamectl command through the terminal, but you can also use the graphical user interface or edit the /etc/hostname file directly. Just remember to restart your system after making any changes for them to take effect.

Hopefully, this article has been able to provide you with all the information you need. Good luck!