YouTube Icon

Code Playground.

How to Change Hostname on CentOS 7

CFG

How to Change Hostname on CentOS 7

This instructional exercise guides you through the way toward changing a hostname on a CentOS 7 framework. 

The hostname is set when the CentOS working framework is introduced or in the event that you are turning up a virtual machine it is progressively alloted to the example at startup. 

The strategies depicted in this instructional exercise will work without the need of restarting your framework. 

Prerequisites

Prior to proceeding with this instructional exercise, ensure you are signed in as a client with sudo advantages . 

Understanding Host Names

A hostname is a mark that distinguishes a machine on an organization. You shouldn't utilize the equivalent hostname on two distinct machines on a similar organization. 

There are three classes of hostname: static, pretty, and transient. 

static - The conventional hostname, which can be set by the client, and is put away in the/and so forth/hostname record. 

pretty - A freestyle UTF8 hostname utilized for introduction to the client. For instance Linuxize's work area. 

transient - A dynamic hostname kept up by the part which can be changed by DHCP or mDNS worker at run time. Of course, it is equivalent to the static hostname. 

It is prescribed to utilize a completely qualified space name (FQDN ) for both static and transient names, for example, host.example.com. 

Display the Current Hostname

To see the current hostname, enter the accompanying order: 

hostnamectl

As should be obvious from the picture over, the current hostname is set to localhost.localdomain. 

Change the Hostname

Technique 1: Using the hostnamectl order 

In CentOS 7 we can change the framework hostname and related settings utilizing the order hostnamectl, the punctuation is as per the following: 

sudo hostnamectl set-hostname host.example.com
sudo hostnamectl set-hostname "Your Pretty HostName" --pretty
sudo hostnamectl set-hostname host.example.com --static
sudo hostnamectl set-hostname host.example.com --transient

For instance is we need to change the framework static hostname to host.linuxize.com, we can utilize the accompanying order: 

sudo hostnamectl set-hostname host.linuxize.com

To set the pretty hostname to Linuxize's work area, enter: 

sudo hostnamectl set-hostname "Linuxize's desktop" --pretty

The hostnamectl order doesn't deliver yield. On progress, 0 is restored, a non-zero disappointment code in any case. 

Method 2: Using the nmtui command

nmtui is a book UI for the NetworkManager which can likewise be utilized to change the hostname. 

To begin the nmtui utility run the accompanying order: 

sudo nmtui

Utilize the bolt keys to explore through the alternatives, select Set framework hostname and press Enter: 

CentOS nmtui 

Set your new hostname: 

CentOS change hostname 

Press enter to affirm the hostname change: 

CentOS set hostname 

At long last, restart the systemd-hostnamed administration for the progressions to produce results: 

sudo systemctl restart systemd-hostnamed

Strategy 3: Using the nmcli order 

nmcli is an order line instrument for controlling the NetworkManager which can likewise be utilized to change the hostname. 

To see the current hostname type: 

sudo nmcli general hostname

To change the hostname to host.linuxize.com utilize the accompanying order: 

sudo nmcli general hostname host.linuxize.com

At long last, restart the systemd-hostnamed administration for the progressions to produce results: 

sudo systemctl restart systemd-hostnamed

 Verify the change

To confirm that the hostname was effectively changed, utilize the hostnamectl order: 

hostnamectl

Your new hostname will be imprinted on the support: 

   Static hostname: host.linuxize.com
   Pretty hostname: Linuxize's desktop
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 52d6807a6ae34327871ae568f7a1387e
           Boot ID: 4f747d0280d3402abed870d18b6e9a7a
    Virtualization: kvm
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-693.11.6.el7.x86_64
      Architecture: x86-64

Conclusion

In this instructional exercise, we have demonstrated you 3 unique techniques for changing the hostname of your CentOS 7 worker without restarting the machine. 

Don't hesitate to leave a remark in the event that you have any inquiries.




CFG