Oracle Linux 8 (OL8) allows you to change the system’s hostname easily, which is helpful for identifying machines in a network. There are different types of hostnames in Linux, including:
- Static hostname: This is set by the user and remains consistent across reboots.
- Transient hostname: This is assigned dynamically by the system, often during network changes.
- Pretty hostname: A user-friendly, descriptive version of the hostname.
Here’s a step-by-step guide to change the hostname on Oracle Linux 8:
Prerequisites
- Ensure you have root or sudo access to perform these operations.
Step 1: Check the Current Hostname
Before changing the hostname, you might want to see the current hostname of the system.
- Open a terminal.
- Run the following command:
hostnamectl status
This command will display the current hostname and other details about the system.
Step 2: Set the New Hostname
You can change the hostname using the hostnamectl
command.
- To set a new hostname, use the following syntax:
sudo hostnamectl set-hostname <new-hostname>
For example, to change the hostname to server01
:
sudo hostnamectl set-hostname server01
- Optionally, you can set a pretty hostname:
sudo hostnamectl set-hostname "My Server" --pretty
Step 3: Verify the Change
After setting the hostname, verify that the new hostname is applied by using:
hostnamectl status
The output should reflect the new hostname.
Step 4: Update the /etc/hosts
File
It’s a good practice to update the /etc/hosts
file to reflect the new hostname, especially if you have static IP mappings. Follow these steps:
- Open the
/etc/hosts
file using any text editor, such asvi
ornano
:
sudo nano /etc/hosts
- Find the line that maps the current hostname to the system’s IP, which might look something like this:
127.0.0.1 localhost
127.0.1.1 old-hostname
- Replace
old-hostname
with the new hostname:
127.0.0.1 localhost
127.0.1.1 server01
- Save the file and exit the editor.
Step 5: Reboot the System (Optional)
While this step is not mandatory, it ensures that all services are using the updated hostname. To reboot the system, use:
sudo reboot
Step 6: Verify After Reboot
Once the system is back online, verify the hostname change once more:
hostnamectl status
Alternative: Temporarily Change Hostname
If you need to change the hostname temporarily (which will not persist after reboot), you can simply use the hostname
command:
sudo hostname <new-hostname>
To verify the temporary change:
hostname
Remember, this change will revert back to the original hostname after a reboot unless the hostnamectl
command is used for a permanent change.
Troubleshooting
- Hostname not updating after reboot: Ensure that the
/etc/hostname
file is correctly updated by thehostnamectl
command. If necessary, manually edit the file:
sudo nano /etc/hostname
Enter the desired hostname and save the file.
- DNS conflicts: Ensure that the new hostname is properly configured in your DNS settings to avoid issues with network identification.
This guide should help you successfully change the hostname on Oracle Linux 8. If you need further customization or have specific network settings, adjust accordingly.