How to change hostname in OpenSUSE

Endrit Qerreti

Endrit Qerreti

In this tutorial, you will learn how to change the hostname on OpenSUSE.

Changing hostname on OpenSUSE is easy, and it can be done in multiple different methods. In this tutorial, we'll be changing the hostname of our machine, by editing the hostname file, and by using the hostnamectl command.

Step 1 - View current hostname

Before you set another hostname, I'd recommend you check what your actual hostname of your machine is. To check the current hostname, you can view the content of the hostname file.

Hostname file is located on /etc/hostname, to view the content of this file, you can use the cat command

cat /etc/hostname


Note: This is not the only way to know the hostname of your machine. You can also use the hostname command, without having to read the content of the hostname file. The idea of reading the content from /etc/hostname is to help you understand where the hostname file is located on your system.

View the current hostname, by using the hostname command


Step 2 - Change Hostname

Just like there are many ways to show the current hostname, changing hostname can also be done in different ways.

One way of changing your machine's hostname is by editing the hostname file, and setting a new hostname there.

To set a new hostname to /etc/hostname , first you need to open the hostname file with a text editor

sudo nano /etc/hostname

Once the hostname file is opened on your text editor, proceed to edit or set a new hostname .

For example our hostname is called opensuse , say we wanted to change this hostname to opensuse-owlhowto then we'd need to replace opensuse with the new hostname.

Next, save the new hostname you set, by pressing CTRL + X, confirm with Yes, finally press enter to confirm and write the changes to hostname file.

Another way of changing your hostname, is by using the hostnamectl command.

sudo hostnamectl set-hostname opensuse

Note: opensuse is the name of the hostname that we are setting for our machine.

Step 3 - Edit /etc/hosts file

After setting the new hostname, make sure to set the same hostname on /etc/hosts file.

To do this, first you need to open the hosts file with a text editor

sudo nano /etc/hosts

You should see a similar output

In our case opensuse is the hostname of our machine.

So, to change opensuse to opensuse-owlhowto we need to replace opensuse

to opensuse-owlhowto

Then, save changes once done.

Step 4 - Reboot

Finally, you need to reboot in order for changes to take effect.



By now you should know how you can change the hostname of your machine on OpenSUSE.