How you can Change Hostname on CentOS eight

How you can Change Hostname on CentOS eight

All

Linux Articles / All 28 Views comments

Sometimes the hostname is about through the set up of the working system or dynamically assigned to the digital machine when it's created.

There are a selection of explanation why chances are you'll want to vary the hostname. The most typical is when the hostname is routinely set upon the occasion creation.

This information explains easy methods to set or change the hostname on CentOS eight without having to restart the system.

Conditions

Earlier than persevering with with this tutorial, be sure to are logged in as a user with sudo privileges.

Understanding Host Names

A hostname is a label that identifies a tool on a community. You shouldn’t have two or extra machines with the identical hostname, on the identical community.

There are three courses of hostname: static, fairly, and transient.

  • static - The normal hostname. It's saved within the /and so on/hostname file and might be set by the consumer.
  • fairly - A free-form UTF8 hostname used for presentation to the consumer. For instance, Linuxize's desktop.
  • transient - A dynamic hostname that's maintained by the kernel. DHCP or mDNS servers can change the transient hostname at run time. By default, it's the similar because the static hostname.

It is suggested to make use of a fully-qualified area identify (FQDN) for each static and transient names akin to host.instance.com.

Displaying the Present Hostname

To view the present hostname, execute the next command:

hostnamectl

On this instance, the present hostname is about to centos8.localdomain.

Altering the Hostname

Technique 1: Utilizing the hostnamectl command

In CentOS eight and all different Linux distributions which are utilizing systemd, you possibly can change the system hostname and associated settings with the hostnamectl command. The syntax is as follows:

sudo hostnamectl set-hostname host.instance.com
sudo hostnamectl set-hostname "Your Fairly HostName" --pretty
sudo hostnamectl set-hostname host.instance.com --static
sudo hostnamectl set-hostname host.instance.com --transient

For instance, to vary the system static hostname to host.linuxize.com, you'd use the next command:

sudo hostnamectl set-hostname host.linuxize.com

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

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

The hostnamectl command doesn't produce output. On success, zero is returned, a non-zero failure code in any other case.

To confirm that the hostname was efficiently modified, use the hostnamectl command.

Technique 2: Utilizing the nmtui command

nmtui is a curses-based device for interacting with NetworkManager. It may also be used to set or change the hostname.

Launch the device by typing its identify within the terminal:

sudo nmtui

Use the arrow keys to navigate by means of the choices, choose Set system hostname and press Enter:

Sort the brand new hostname:

Press Enter to verify the brand new hostname:

Lastly, restart the systemd-hostnamed service for the modifications to take impact:

sudo systemctl restart systemd-hostnamed

Technique three: Utilizing the nmcli command

nmcli is a command-line software for controlling the NetworkManager and may also be used to vary the system’s hostname.

To view the present hostname, sort:

sudo nmcli g hostname

To vary the hostname to host.linuxize.com use the next command:

sudo nmcli g hostname host.linuxize.com

For the modifications to take impact, restart the systemd-hostnamed service:

sudo systemctl restart systemd-hostnamed

Conclusion

To set or change the hostname on CentOS system, use the hostnamectl set-hostname command adopted by the brand new hostname.

Be happy to go away a remark when you've got any questions.

Comments