OpenSUSE Linux Change Hostname (computer name) command

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 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

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

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.

This entry is 14 of 15 in the Linux/Unix Set hostname Tutorial series. Keep reading the rest of the series:

  1. Ubuntu Linux Change Hostname (computer name)
  2. Debian Linux: Change Hostname / Computer Name Permanently
  3. Linux change my hostname / computer system name
  4. Linux Change Hostname
  5. RHEL / Centos Linux 7: Change and Set Hostname Command
  6. OpenBSD Change Hostname
  7. CentOS Linux 5/6 Change Hostname Command
  8. Linux setting hostname and domain name of my server
  9. FreeBSD Change Hostname without reboot
  10. SuSe Linux Change Hostname without reboot
  11. How to set the hostname on Fedora Linux
  12. Ubuntu 18.04 LTS change hostname permanently
  13. Ubuntu set hostname permanently (computer name) command
  14. OpenSUSE Linux set hostname permanently (computer name) command
  15. RHEL 8 Linux set hostname permanently (computer name) command

Posted by: SXI ADMIN

The author is the creator of SXI LLC 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.