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:
OpenSUSE Linux change hostname command
The procedure to change the computer name on OpenSUSE Linux:
- Type the following command to edit /etc/hostname using nano or vi text editor:
sudo vi /etc/hostname
- Delete the old name and setup new name.
- Next Edit the /etc/hosts file:
sudo vi /etc/hosts
- Replace any occurrence of the existing computer name with your new one.
- Reboot the system to changes take effect:
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
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:
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
Machine ID: a5f03d6b3355446988c7d732ca104a43
Boot ID: c00a7dcbb5d2473ba68059416570f1d5
Operating System: openSUSE Leap 15.0
CPE OS Name: cpe:/o:opensuse:leap:15.0
Kernel: Linux 4.12.14-lp150.12.25-default
To change hostname from linux-mig6 to suse-nixcraft, enter:
$ sudo hostnamectl set-hostname ln-sg-vpn1
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.