During installation, openSUSE and SLES assign a default hostname to the system if not set manually. This default hostname typically starts with linux- followed by random characters. Changing this hostname is a simple process that can be done through the terminal.
The system's hostname information is stored in the /etc/hostname file. You can modify this file directly to change the hostname. Alternatively, you can use the hostnamectl command, which is a standard tool available in most Linux distributions.
After changing the hostname, it may not immediately appear in your shell prompt. The shell prompt updates only when a new session is started. Understanding this ensures accurate verification of the hostname change.
Steps to change hostname in openSUSE and SLES:
- Open the Terminal application.
- Display the current hostname.
user@linux-ui1m:~> hostname linux-ui1m
hostname is normally displayed in at the shell prompt via \h in the $PS1 environment variable.
- Change the hostname using the hostnamectl command.
user@linux-ui1m:~> sudo hostnamectl set-hostname host [sudo] password for root:
- Verify the new hostname by displaying it again.
user@linux-ui1m:~> hostname host
The shell prompt is not immediately updated as $PS1 is only set when a new shell is started
- Start a new shell session to reflect the updated hostname.
user@linux-ui1m:~> bash user@host:~>

Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
Comment anonymously. Login not required.