The System Name aka Hostname, is often set during the installation of the operating system by the system administrator or by the system build admin. But, sometimes, we may need to change the hostname name of servers for our requirements.
This guide will help you to set/change hostname in CentOS 8 / RHEL 8.
The hostname can be,
- 64 character in a length
- Recommend to have FQDN
- Consists of a-z, A-Z, 0-9, “-”, “_” and “.” only
Change hostname in CentOS 8 / RHEL 8
Contents
We can change the hostname using different methods.
1. Using hostnamectl command
2. Using nmtui tool
3. Editing /etc/hostname file
Before you change the hostname, let’s check the current hostname.
[root@localhost ~]# hostname
Output:
localhost.localdomain
hostnamectl command
hostnamectl is used to change the hostname without rebooting the system.
Use the hostnamectl to change the hostname as it is far better than other methods and does not require to update the kernel about the change in the hostname.
[root@localhost ~]# hostnamectl status
Output:
Static hostname: localhost.localdomain Icon name: computer-vm Chassis: vm Machine ID: a35862c3f73f451cbdf15fd2336fefcb Boot ID: 7e4c96cea89f40b8817d9a9cae1bc82d Virtualization: oracle Operating System: CentOS Linux 8 (Core) CPE OS Name: cpe:/o:centos:centos:8 Kernel: Linux 4.18.0-80.el8.x86_64 Architecture: x86-64
Set the hostname.
[root@localhost ~]# hostnamectl set-hostname client.itzgeek.local
Recheck the hostname (Close the session and open a new session using putty or console)
[root@client ~]# hostnamectl status
Output:
Static hostname: client.itzgeek.local Icon name: computer-vm Chassis: vm Machine ID: a35862c3f73f451cbdf15fd2336fefcb Boot ID: 7e4c96cea89f40b8817d9a9cae1bc82d Virtualization: oracle Operating System: CentOS Linux 8 (Core) CPE OS Name: cpe:/o:centos:centos:8 Kernel: Linux 4.18.0-80.el8.x86_64 Architecture: x86-64
OR
[root@client ~]# hostname
Output:
client.itzgeek.local
nmtui tool
NetworkManager tool (yum install -y NetworkManager-tui) is used to set the static hostname in /etc/hostname file.
nmtui
Select Set HostName
Set the hostname.
Hostname has been set.
Exit from the tool.
Check the hostname with the below commands.
[root@localhost ~]# hostname client.itzgeek.local
[root@localhost ~]# cat /etc/hostname client.itzgeek.local
/etc/hostname file
This method is simple but requires a reboot of the server to take effect.
Edit the /etc/hostname file.
vi /etc/hostname
Add the hostname, as shown below.
client.itzgeek.local
Reboot the machine to update the kernel about the change in the hostname.
reboot
Conclusion
That’s All. Please share your feedback in the comments section.