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
$ 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: localhost
To: 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: linux-ixcp
         Icon name: computer-laptop
           Chassis: laptop
        Machine ID: 3d08939b17f74e098bc15791dcf2b90f
           Boot ID: 58ad4eb4b70649889cdaaf1c688f601b
  Operating System: openSUSE Leap 15.1
       CPE OS Name: cpe:/o:opensuse:leap:15.1
            Kernel: Linux 4.12.14-lp151.28.7-default
      Architecture: x86-64

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


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.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 0 comments... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
0 comments… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum