The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,967 other subscribers

How to change system hostname in SUSE

Posted by jpluimers on 2022/01/21

The proper way is not manually changing /etc/hostname, but running this::

hostnamectl set-hostname host

[Wayback] How to change system hostname in SUSE

Background information in [Wayback] linux – What’s the point of the hostnamectl command? – Unix & Linux Stack Exchange (with a great answer by [Wayback] slm, edited by me for Wayback machine links):


hostnamectl is part of systemd, and provides a proper API for dealing with setting a server’s hostnames in a standardized way.

$ rpm -qf $(type -P hostnamectl)

Previously each distro that did not use systemd, had their own methods for doing this which made for a lot of unnecessary complexity.

  hostnamectl may be used to query and change the system hostname and
  related settings.

  This tool distinguishes three different hostnames: the high-level 
  "pretty" hostname which might include all kinds of special characters 
  (e.g. "Lennart's Laptop"), the static hostname which is used to
  initialize the kernel hostname at boot (e.g. "lennarts-laptop"), and the 
  transient hostname which is a default received from network 
  configuration. If a static hostname is set, and is valid (something
   other than localhost), then the transient hostname is not used.

   Note that the pretty hostname has little restrictions on the characters 
   used, while the static and transient hostnames are limited to the 
   usually accepted characters of Internet domain names.

   The static hostname is stored in /etc/hostname, see hostname(5) for 
   more information. The pretty hostname, chassis type, and icon name are 
   stored in /etc/machine-info, see machine-info(5).

   Use systemd-firstboot(1) to initialize the system host name for mounted 
   (but not booted) system images.

hostnamectl also pulls a lot of disparate data together into a single location to boot:

$ hostnamectl
   Static hostname: centos7
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 1ec1e304541e429e8876ba9b8942a14a
           Boot ID: 37c39a452464482da8d261f0ee46dfa5
    Virtualization: kvm
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-693.21.1.el7.x86_64
      Architecture: x86-64

The info here is coming from /etc/*releaseuname -a, etc. including the hostname of the server.

What about the files?

Incidentally, everything is still in files, hostnamectl is merely simplifying how we have to interact with these files or know their every location.

As proof of this you can use strace -s 2000 hostnamectl and see what files it’s pulling from:

$ strace -s 2000 hostnamectl |& grep ^open | tail -5
open("/lib64/", O_RDONLY|O_CLOEXEC) = 3
open("/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
open("/proc/self/stat", O_RDONLY|O_CLOEXEC) = 3
open("/etc/machine-id", O_RDONLY|O_NOCTTY|O_CLOEXEC) = 4
open("/proc/sys/kernel/random/boot_id", O_RDONLY|O_NOCTTY|O_CLOEXEC) = 4


To the astute observer, you should notice in the above strace that not all files are present. hostnamectl is actually interacting with a service, systemd-hostnamectl.service which in fact does the “interacting” with most of the files that most admins would be familiar with, such as /etc/hostname.

Therefore when you run hostnamectl you’re getting details from the service. This is a ondemand service, so you won’t see if running all the time. Only when hostnamectl runs. You can see it if you run a watch command, and then start running hostnamectl multiple times:

$ watch "ps -eaf|grep [h]ostname"
root      3162     1  0 10:35 ?        00:00:00 /usr/lib/systemd/systemd-hostnamed

The source for it is here: [Wayback] and if you look through it, you’ll see the references to /etc/hostname etc.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: