CentOSRHEL Based

How To Change Hostname on CentOS Stream 10

Change Hostname on CentOS Stream 10

In the world of Linux administration, managing hostnames is a fundamental task that can significantly impact system organization and network management. A hostname serves as a unique identifier for a device on a network, making it essential for communication between systems. This article provides a comprehensive guide on how to change the hostname in CentOS Stream 10, ensuring that you have the necessary knowledge and tools to perform this task efficiently.

Understanding Hostnames

Definition of Hostname

A hostname is a human-readable label assigned to a device connected to a network. It is used to identify the device in various networking contexts. In Linux, there are three types of hostnames:

  • Static Hostname: The permanent name assigned to the system, typically defined in configuration files.
  • Transient Hostname: A temporary name assigned during the system’s current session, often used when connected to different networks.
  • Pretty Hostname: A more descriptive name that can include spaces and special characters, making it easier for users to understand the purpose of the device.

Importance of Hostnames

Hostnames play a crucial role in network identification and management. They allow users and administrators to easily recognize devices without needing to remember complex IP addresses. Furthermore, a well-organized hostname structure can enhance system management and improve overall network efficiency.

Prerequisites for Changing Hostname

Access Requirements

To change the hostname on CentOS Stream 10, you must have root or sudo privileges. This ensures that you have the necessary permissions to modify system settings.

Backup Considerations

Before making any changes, it is advisable to back up important configuration files. Key files to consider include:

  • /etc/hostname
  • /etc/hosts

You can create backups using the following commands:

sudo cp /etc/hostname /etc/hostname.bak
sudo cp /etc/hosts /etc/hosts.bak

Methods to Change Hostname in CentOS Stream 10

Using the hostnamectl Command

Overview of hostnamectl

The hostnamectl command is part of the systemd suite and provides an easy way to manage hostnames on Linux systems. It allows you to view and set both static and transient hostnames.

Step-by-Step Instructions

    1. Check Current Hostname: Before changing your hostname, check the current one by running:
hostnamectl
    1. Set New Static Hostname: To change the static hostname, use the following command, replacing new-hostname with your desired name:
sudo hostnamectl set-hostname new-hostname
    1. Verify Changes: After setting the new hostname, confirm that it has been updated by running:
hostnamectl

Edit Configuration Files Directly

Edit /etc/hostname

If you prefer manual editing, you can change the hostname directly in configuration files. Start by editing the /etc/hostname file:

sudo nano /etc/hostname

This file typically contains a single line with the current hostname. Replace it with your new hostname and save changes (in nano, press CTRL + X, then Y, followed by ENTER).

Edit /etc/hosts

The next step involves updating the /etc/hosts file. Open it using your preferred text editor:

sudo nano /etc/hosts

You will see lines similar to this:

127.0.0.1   localhost
127.0.0.1   old-hostname

Edit the line associated with `127.0.0.1` to reflect your new hostname:

127.0.0.1   localhost
127.0.0.1   new-hostname

Save and exit the editor.

Using NetworkManager TUI (nmtui)

Overview of nmtui

The NetworkManager Text User Interface (TUI) provides an intuitive way to manage network settings, including hostnames.

Step-by-Step Instructions

    1. Launch nmtui:
sudonmtui
    1. Select “Set system hostname”:

This option allows you to enter your desired hostname directly into a user-friendly interface.

    1. Add New Hostname:

Add your new hostname and save changes before exiting.

Temporary Hostname Changes

Using the hostname Command

If you need to change the hostname temporarily (for example, during testing), you can use the following command:

sudo hostname new-temporary-hostname

This change will last until the next reboot; after that, the system will revert to its original static hostname.

Verifying the Changes

How to Check Current Hostname

hostnamectl
hostname

Reboot Considerations

A reboot is not always necessary after changing your hostname using `hostnamectl`. However, if you encounter issues with certain applications or services recognizing the new hostname, consider rebooting your system for full effect.

Troubleshooting Common Issues

Hostname Not Updating

If you find that your hostname hasn’t changed after following these steps, consider checking for typos in your commands or configuration files. Ensure that you’ve saved all changes properly and that you’re using sudo privileges where necessary.

Network Issues Post Change

  • Purge any DNS caches on client machines that may still be referencing the old hostname.
  • If applicable, update any firewall rules or security settings that may be tied to specific hostnames.
  • If using DHCP reservations based on hostnames, ensure they are updated accordingly.

Congratulations! You have successfully changed the Hostname. Thanks for using this tutorial to change the Hostname on your CentOS Stream 10 system. For additional or useful information, we recommend you check the official CentOS Stream website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button