Site icon OpenClassTech

Detailed Guide: How to Change the Hostname in Oracle Linux 8

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:

Here’s a step-by-step guide to change the hostname on Oracle Linux 8:

Prerequisites

Step 1: Check the Current Hostname

Before changing the hostname, you might want to see the current hostname of the system.

  1. Open a terminal.
  2. 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.

  1. 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
  1. 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:

  1. Open the /etc/hosts file using any text editor, such as vi or nano:
   sudo nano /etc/hosts
  1. 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
  1. Replace old-hostname with the new hostname:
   127.0.0.1   localhost
   127.0.1.1   server01
  1. 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

  1. Hostname not updating after reboot: Ensure that the /etc/hostname file is correctly updated by the hostnamectl command. If necessary, manually edit the file:
   sudo nano /etc/hostname

Enter the desired hostname and save the file.

  1. 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.

Exit mobile version