One of basics things you should be able to do after installing a Centos 8 is to know how to change the hosname of your server. In this quick tutorial, we will explain how to change the hostname on your CentOS 8 Linux server using four methods:
1. nmtui Tool ( Network Configuration Using a Text User Interface)
2. nmcli Tool ( NetworkManager Command Line )
3. hostnamectl Tool
4. Editing /etc/hostname
Change Hostname on CentOS 8
1./ nmtui tool:
The nmtui Tool ( Network Configuration Using a Text User Interface) is used to set a static host name in /etc/hostname .
1- Open your terminal and type nmtui
, and you going to see the below interface:
02- Next, set the hostname and click ok
.
03- When you done, restart the hostnamed
to apply the hostname changing as below:
# systemctl restart systemd-hostnamed
2./ nmcli tool:
1- First, let’s check the current hostname by typing the below command:
# nmcli general hostname server
2- Now, let’s change the host name as below:
# nmcli general hostname client.yallalabs.com
3- Finally, restart the hostnamed
to make sure the change takes effect:
# systemctl restart systemd-hostnamed
3./ hostnamectl tool:
When we use hostnamectl tool to change the host name of our server, it’s not required to restart the hostnamed or to reboot the server to ensure the change takes an effect.
01- First, let’s check the current hostname of the CentOS server:
# hostnamectl status Static hostname: server Icon name: computer-vm Chassis: vm Machine ID: 63e2c28ecd6348a3a956f74fc02f6d84 Boot ID: 840a0e1bc90b4ac3974bb5b5cc0b20cc Virtualization: kvm Operating System: CentOS Linux 7 (Core) CPE OS Name: cpe:/o:centos:centos:7 Kernel: Linux 3.10.0-327.el7.x86_64 Architecture: x86-64
02-Seconde, Let’s change the hostname as below:
# hostnamectl set-hostname client.yallalabs.com
03- Finally, let’s check if changes takes effects.
# hostnamectl status Static hostname: client.yallalabs.com Icon name: computer-vm Chassis: vm Machine ID: 63e2c28ecd6348a3a956f74fc02f6d84 Boot ID: 840a0e1bc90b4ac3974bb5b5cc0b20cc Virtualization: kvm Operating System: CentOS Linux 7 (Core) CPE OS Name: cpe:/o:centos:centos:7 Kernel: Linux 3.10.0-327.el7.x86_64 Architecture: x86-64
4./ Edit /etc/hostname:
1- First, open the /etc/hostname
and modify the hostname:
# vi /etc/hostname
2- Finally, as we mentioned before we need to restart hostnamed
by running the below command:
# systemctl restart systemd-hostnamed
Conclusion
That’s it! You have learned how to change the hostname on CentOS 8 server using different methods, using nmtui Tool (Network Configuration Using a Text User Interface), nmcli Tool (NetworkManager Command Line), hostnamectl Tool or by editing /etc/hostname
You might want to check the following guides: