YouTube Icon

Code Playground.

How to Change Hostname on CentOS 8

CFG

How to Change Hostname on CentOS 8

Normally the hostname is set during the establishment of the working framework or progressively appointed to the virtual machine when it is made. 

There are various reasons why you may need to change the hostname. The most widely recognized is the point at which the hostname is naturally set upon the case creation. 

This guide discloses how to set or change the hostname on CentOS 8 without expecting to restart the 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 name that recognizes a gadget on an organization. You shouldn't have at least two machines with the equivalent hostname, on a similar organization. 

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

  • static - The customary hostname. It is put away in the/and so on/hostname document and can be set by the client. 
  • pretty - A freestyle UTF8 hostname utilized for introduction to the client. For instance, Linuxize's work area. 
  • transient - A dynamic hostname that is kept up by the portion. DHCP or mDNS workers can change the transient hostname at run time. Naturally, it is equivalent to the static hostname. 

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

Displaying the Current Hostname

To see the current hostname, execute the accompanying order: 

hostnamectl

In this model, the current hostname is set to centos8.localdomain. 

Changing the Hostname

Strategy 1: Using the hostnamectl order 

In CentOS 8 and all other Linux circulations that are utilizing systemd, you can change the framework hostname and related settings with the hostnamectl order. The language structure 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, to change the framework static hostname to host.linuxize.com, you would utilize the accompanying order: 

sudo hostnamectl set-hostname host.linuxize.com

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

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

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

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

Method 2: Using the nmtui command

nmtui is a condemnations based instrument for collaborating with NetworkManager. It can likewise be utilized to set or change the hostname. 

Dispatch the instrument by composing its name in the terminal: 

sudo nmtui

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

Type the new hostname: 

Press Enter to affirm the new hostname: 

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

sudo systemctl restart systemd-hostnamed

Method 3: Using the nmcli command

nmcli is an order line device for controlling the NetworkManager and can likewise be utilized to change the framework's hostname. 

To see the current hostname, type: 

sudo nmcli g hostname

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

sudo nmcli g hostname host.linuxize.com

For the progressions to produce results, restart the systemd-hostnamed administration: 

sudo systemctl restart systemd-hostnamed

Conclusion

To set or change the hostname on CentOS framework, utilize the hostnamectl set-hostname order followed by the new hostname. 

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




CFG