November 24, 2020
How to change hostname on CentOS 8

How To Change Hostname On CentOS 8

On this article we will discuss how to change hostname on CentOS 8 system, for Ubuntu system has been discussed on How to change hostname on Ubuntu 18.04 LTS article.

Introduction

When we install CentOS, we usually leave our computer name as default as ‘localhost’. But not a few administrators have defined a hostname or one is automatically created. A hostname is a label that is assigned to a device connected to a computer network and that is used to identify the device in various forms of electronic communication. In this article, we will explain how to change the previously deployed hostname to another new name.

There are several ways to change the hostname. At least there are two different option, whether it requires a restart or not. We will try to change hostname with these two options : without restarting and with restarting.



Prerequisites

  • CentOS 8 / RHEL system
  • A user with Sudo or root permissions
  • Any built-in text editor

Display Current Hostname

Before changing existing hostname to new one, we have to displya current existing hostname of our CentOS system. For this purpose we have to subnit the command line : hostname or hostnamectl.

  • hostname, is used to display the system’s DNS name, and to display or set its hostname or NIS domain name.
[mpik@localhost ~]$ hostname
localhost.localdomain
hostname command line
  • hostnamectl is used to to query and change the system hostname and related settings.
[mpik@localhost ~]$ hostnamectl
Static hostname: localhost.localdomain
Icon name: computer-vm
Chassis: vm
Machine ID: 53f163df923e4d3fa2cd80e8ddde10a0
Boot ID: 2cccbe061db544caa91ae0e1f88008ef
Virtualization: vmware
Operating System: CentOS Linux 8 (Core)
CPE OS Name: cpe:/o:centos:centos:8
Kernel: Linux 4.18.0-193.el8.x86_64
Architecture: x86-64
hostnamectl command line

Change Hostname

On this section we will learn how to change the system hostname from existing to the new one. As mentioned early on this article we will change the hostname with two option : With Restart the system and without restarting system.

Changing Hostname Without Restarting System

hostnamectl command line
Format to use this command is : sudo hostnamectl set-hostname new_hostname
Example : sudo hostnamectl set-hostname diginetapp02, changing existing hostname to diginetapp02.

[mpik@localhost ~]$ sudo hostnamectl set-hostname diginetapp02
[sudo] password for mpik:
[mpik@localhost ~]$ hostnamectl
Static hostname: diginetapp02
Icon name: computer-vm
Chassis: vm
Machine ID: 53f163df923e4d3fa2cd80e8ddde10a0
Boot ID: 2cccbe061db544caa91ae0e1f88008ef
Virtualization: vmware
Operating System: CentOS Linux 8 (Core)
CPE OS Name: cpe:/o:centos:centos:8
Kernel: Linux 4.18.0-193.el8.x86_64
Architecture: x86-64

mntui tools

nmtui is actually used a tools for Network related, but it can be used to update the hostname. nmtui is a curses‐based TUI application for interacting with NetworkManager. For using this tool, just hit the command line nmtui, then follow the steps inside it.

[mpik@localhost ~]$ sudo nmtui



Changing Hostname With Restarting System

Updating /etc/hosts file is the method most people use. Because it will give us a sense of psychological, if we had changed the hostname of a node system. We only need a root permission for editing this file and a text editor. To take effect after editing this file, we have to restart the system.

[mpik@diginetapp02 ~]$ sudo vi /etc/hosts
[sudo] password for mpik:
[mpik@diginetapp02 ~]$ sudo reboot 0

After editing the we have to reboot the system.

Conclusion

On this article, we have learnt how to change/update the hostname of CentOS 8 system.

Share this article via :

Leave a Reply

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