OpenSUSE Linux Change Hostname (computer name) command

last updated in Categories ,

I am a new OpenSUSE Linux user and setup a server at Linode cloud. They setup my server name to ‘localhost’ during deplyoment but now I would like to change the computer name to something else. How can I remove old name and set it to ‘ln-sg-vpn1’ on OpenSUSE Linux? Can you tell me how do I change the OpenSUSE Linux computer name? How do I assign a static hostname to server running openSUSE Leap 15.0?

Introduction : For OpenSUSE Linux you can use the hostnamectl command to change the hostname of an OpenSUSE Linux server, laptop or desktop. You can use the hostname command to see or set the system’s hostname too. The hostname or computer name is usually at system startup in /etc/hostname file. Open the terminal application and type the following command to change the hostname on OpenSUSE Linux.

Display the current Suse Linux hostname

Type any one of the following command:
$ hostname
OR
$ hostnamectl
OpenSUSE Linux show or display current hostname

OpenSUSE Linux change hostname command

The procedure to change the computer name on OpenSUSE Linux:

  1. Type the following command to edit /etc/hostname using nano or vi text editor:
    sudo vi /etc/hostname
  2. Delete the old name and setup new name.
  3. Next Edit the /etc/hosts file:
    sudo vi /etc/hosts
  4. Replace any occurrence of the existing computer name with your new one.
  5. Reboot the system to changes take effect:
    sudo reboot

How to change the OpenSUSE Linux server hostname without a system restart?

Type the following commands:
$ sudo hostname ln-sg-vpn1
Next edit the /etc/hostname file and update hostname:
$ sudo vi /etc/hostname
Finally, edit the /etc/hosts file and update the lines that reads your old-host-name:
$ sudo vi /etc/hosts
From:
127.0.1.1 localhost
To:
127.0.1.1 ln-sg-vpn1
Save and close the file.

A note about hostnamectl command

Systemd based Linux distor such as OpenSUSE Linux can simply use the hostnamectl command to rename hostname. To see current setting just type:
$ hostnamectl
Sample outputs:

   Static hostname: localhost
         Icon name: computer-vm
           Chassis: vm
        Machine ID: a5f03d6b3355446988c7d732ca104a43
           Boot ID: c00a7dcbb5d2473ba68059416570f1d5
    Virtualization: kvm
  Operating System: openSUSE Leap 15.0
       CPE OS Name: cpe:/o:opensuse:leap:15.0
            Kernel: Linux 4.12.14-lp150.12.25-default
      Architecture: x86-64

To change hostname from linux-mig6 to suse-nixcraft, enter:
$ sudo hostnamectl set-hostname ln-sg-vpn1
$ hostnamectl

How to set or change OpenSUSE Linux server hostname

Conclusion

On OpenSUSE Linux one can use the hostnamectl command to control the system hostname and set a new name as well and this is recommend for all users.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.