Changing the hostname of your CentOS Stream system is a straightforward process that can be accomplished in a few simple steps. The hostname is an important aspect of your system’s network configuration, as it identifies your machine on a network. In this article, we will guide you through the steps to change the hostname on CentOS Stream.
Prerequisites
Before we begin, make sure you have:
- A server running CentOS Stream.
- Root or sudo privileges to make changes to system configuration.
Step 1: Check the Current Hostname
Before changing the hostname, it is useful to check the current hostname of your system. You can do this by using the following command:
$ hostnamectl
This command will display the current hostname along with other system information :
ramansah@localhost ~]$ hostnamectl
Static hostname: (unset)
Transient hostname: localhost
Icon name: computer-vm
Chassis: vm 🖴
Machine ID: 6a37edb5a9e84618a22f410b73f1d0a1
Boot ID: db50ae68bcb84c39acc3e57d2b98a9aa
Virtualization: vmware
Operating System: CentOS Stream 9
CPE OS Name: cpe:/o:centos:centos:9
Kernel: Linux 5.14.0-452.el9.x86_64
Architecture: x86-64
Hardware Vendor: VMware, Inc.
Hardware Model: VMware Virtual Platform
Firmware Version: 6.00
Step 2: Change the Hostname
There are several ways to change the hostname on CentOS Stream. We will cover the most common methods: using hostnamectl
, editing the /etc/hostname
file, and modifying the /etc/hosts
file.
Method 1: Using hostnamectl
The hostnamectl
command is the recommended way to change the hostname on modern systems. It allows you to set the static, pretty, and transient hostnames. To change the static hostname, use the following command:
$ sudo hostnamectl set-hostname new-hostname
Replace new-hostname
with the desired hostname for your system. On this tutorial we will use the hostname to be dev03.infodiginet.
[ramansah@localhost ~]$ sudo hostnamectl set-hostname dev03.infodiginet
[sudo] password for ramansah:
Method 2: Editing the /etc/hostname File
You can also change the hostname by editing the /etc/hostname
file directly. Open the file in your preferred text editor:
sudo vi /etc/hostname
Replace the current hostname with the new dev03.infodiginet
and save the file.
[ramansah@localhost ~]$ sudo vi /etc/hostname
dev03.infodiginet
Method 3: Modifying the /etc/hosts File
It is also a good idea to update the /etc/hosts
file to reflect the new hostname. Open the /etc/hosts
file in your preferred text editor:
[ramansah@localhost ~]$ sudo nano /etc/hosts
#127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
127.0.0.1 dev03.infodiginet dev03.infodiginet.com
~
:wq!
Step 3: Verify the Change
To verify that the hostname has been successfully changed, you can use the hostnamectl
command again:
[ramansah@localhost ~]$ hostnamectl
Static hostname: dev03.infodiginet
Icon name: computer-vm
Chassis: vm 🖴
Machine ID: 6a37edb5a9e84618a22f410b73f1d0a1
Boot ID: db50ae68bcb84c39acc3e57d2b98a9aa
Virtualization: vmware
Operating System: CentOS Stream 9
CPE OS Name: cpe:/o:centos:centos:9
Kernel: Linux 5.14.0-452.el9.x86_64
Architecture: x86-64
Hardware Vendor: VMware, Inc.
Hardware Model: VMware Virtual Platform
Firmware Version: 6.00
You should see the new hostname displayed in the output.
Step 4: Reboot the System (Optional)
In some cases, you may need to reboot your system for the changes to take effect fully. You can do this with the following command:
ramansah@localhost ~]$ reboot
Conclusion
Changing the hostname on CentOS Stream is a simple process that can be done using the hostnamectl
command, by editing the /etc/hostname
file, or by modifying the /etc/hosts
file. Following the steps outlined in this article, you can easily change your system’s hostname to better suit your network environment.