December 3, 2021
How to change hostname on Rocky Linux 8

How To Change Hostname on Rocky Linux 8

On this article we will learn how to change hostname on Rocky Linux 8.

Introduction

Sometimes, because of a need we have to change the hostname of a server that we manage. In this article, we will learn how to change the hostname of a system which running on the Rocky Linux 8 operating system.

Hostname Change on Rocky Linux 8

There are at least three ways that can be used to change the hostname of a server, namely:

  1. hostnamectl command line
  2. Edit /etc/hosts file
  3. NMTUI tools



1. hostnamectl Command Line

Hostnamectl can be used to query and change the system hostname and related settings. Before changing the hostname, we will query the existing hostname by typing the command line: hostnamectl.

[ramansah@localhost ~]$ hostnamectl
   Static hostname: localhost.localdomain
         Icon name: computer-vm
           Chassis: vm
        Machine ID: b94ae72b25a1402bab6e7762328b0138
           Boot ID: 152a2e9830ac44b592ef8892e822bab1
    Virtualization: vmware
  Operating System: Rocky Linux 8.4 (Green Obsidian)
       CPE OS Name: cpe:/o:rocky:rocky:8.4:GA
            Kernel: Linux 4.18.0-305.3.1.el8_4.x86_64
      Architecture: x86-64

To change the hostname, we can use the command line hostnamectl hostnamectl set-hostname <new_hostname>. On our tutorial we will use otodiginet as new hostname. To execute this command line, we must have root privilege.

[ramansah@localhost ~]$ sudo hostnamectl set-hostname otodiginet

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for ramansah: 
Hostnamectl set-hostname
Hostnamectl set-hostname

2. Edit /etc/hosts file

Another way to change the hostname is to replace it directly in the /etc/hosts file. We can use editor, such as : vi, nano, etc. for updating the file.

File /etc/hosts
File /etc/hosts

To take effect, then we will execute the command line : sudo systemctl restart systemd-hostnamed.

3. NMTUI tools

to use NMTUI tools, we must have root privileges or using sudo. After NMTUI tools is called from the console, then we will be faced with a series of dialog box for changing the hostname.

NMTUI tools | Set system hostname
NMTUI tools | Set system hostname



NMTUI tools | Set Hostname
NMTUI tools | Set Hostname
NMTUI tools | the hostname has been set
NMTUI tools | the hostname has been set

Conclusion

On this articel, we have shown you a simple way to change hostame on Rocky Linux 8.

Share this article via :

Leave a Reply

Your email address will not be published. Required fields are marked *