Changing the hostname on AlmaLinux 8 and CentOS 7 is a straightforward process. The process is quite similar for both operating systems. Below, I’ll outline the steps to change the hostname on AlmaLinux 8 and CentOS 7.
Step 1: Log in as a Superuser
You’ll need superuser (root) privileges to change the hostname. Log in to your AlmaLinux 8 or CentOS 7 server with a superuser account.
Step 2: Check the Current Hostname
Before changing the hostname, it’s a good idea to verify the current hostname. Open your terminal and enter the following command:
hostname
This command will display the current hostname of your system.
Step 3: Change the Hostname
To change the hostname, you’ll need to edit the appropriate configuration files. Here’s how you can do it for both AlmaLinux 8 and CentOS 7:
For AlmaLinux 8:
- Edit the
/etc/hostname
file with your preferred text editor (e.g., nano, vi, vim):
sudo nano /etc/hostname
- Replace the existing hostname with your desired one. Save the file and exit the text editor.
For CentOS 7:
- Edit the
/etc/hostname
file using your preferred text editor (e.g., nano, vi, vim):
sudo nano /etc/hostname
- Replace the existing hostname with your desired one. Save the file and exit the text editor.
Step 4: Update the Current Hostname
To immediately apply the changes to the current hostname, you’ll use the hostnamectl
command for AlmaLinux 8 or the hostname
command for CentOS 7.
For AlmaLinux 8:
Run the following command, replacing newhostname
with your desired hostname:
sudo hostnamectl set-hostname newhostname
For CentOS 7:
Run the following command to set the new hostname, replacing newhostname
with your desired hostname:
sudo hostname newhostname
Step 5: Reboot Your System
To ensure that all system services and applications recognize the new hostname, it’s recommended to reboot your system:
sudo reboot
After the system reboots, the new hostname should be in effect.
Step 6: Verify the Change
To verify that the hostname has been successfully changed, log in to your system and run the following command:
hostname
This command should display your newly set hostname.
In conclusion, changing the hostname on AlmaLinux 8 and CentOS 7 is a straightforward process. By editing the appropriate configuration files and using the hostnamectl
(for AlmaLinux 8) or hostname
(for CentOS 7) commands, you can easily modify your system’s hostname to suit your specific needs.