Oracle by Example brandingOracle Linux: Use the hostnamectl Command to Update the System Hostname

section 0Before You Begin

This tutorial describes how to update the system hostname on an Oracle Linux system using the hostnamectl command from the command line. This tutorial is targeted at Oracle Linux 8 users, but the hostnamectl command can be used on any system configured with Systemd, such as Oracle Linux 7.


Many Oracle Linux systems are installed without a desktop environment. There are usually multiple ways to configure base system settings, such as the system hostname, when working on the command line.

On some other distributions, particularly where Systemd is not used, configuring the system hostname involved editing system files, such as /etc/hostname and /etc/hosts, running the hostname command to set the hostname, and rebooting the system.

Setting the system hostname on Oracle Linux systems with Systemd is easy to do using the hostnamectl command.

What Do You Need?

  • Any Oracle Linux system that uses Systemd

Check the current configuration

To check the current configuration for a system, simply run the hostnamectl command without any parameters. For example:

# hostnamectl
   Static hostname: localhost.localdomain
Transient hostname:                                                                                                                                                      
         Icon name: computer-server                                                                                                                                                                  
           Chassis: server                                                                                                                                                                           
        Machine ID: f8bef1aa7e2e4d43907bdf49ed297f8c                                                                                                                                                 
           Boot ID: 10b41dcd69f6464294308cf4ef632868
  Operating System: Oracle Linux Server 8.0
       CPE OS Name: cpe:/o:oracle:linux:8:0:server
            Kernel: Linux 4.18.0-80.el8.x86_64
      Architecture: x86-64

The system displays some useful information.

Note that in the example output, the system is configured with a Static hostname and a Transient hostname. The static hostname is the default hostname for the system, configured in the /etc/hostname file. The transient hostname is a value that can be set for the system, after boot, by services such as DHCP or mDNS. If no service sets the transient hostname, the system reverts to using the static hostname. The system can also be configured with a Pretty hostname which is a friendly free-form system name that is displayed to a user in user interface environments. Frequently these values are equivalent, but the hostnamectl command can be used to set each of these independently.

It is also useful to note that you can use this command to check the Operating System release and update level as well as the kernel version that is in use.

Set the system hostname

Set all values for the system hostname, by running the following command:

# hostnamectl set-hostname myhost.mydomain

Substitute myhost.mydomain with the value for your system hostname and domain.

You can also set different values for each of the static, transient or pretty hostname values. For example, you can run:

# hostnamectl set-hostname --pretty "My Oracle Linux 8 Server"

System hostname values updated using the hostnamectl command in this way, are effective immediately and do not require the system to reboot.

more informationWant to Learn More?