Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Linux Tutorials»How to Change Hostname (Computer Name) on Fedora & CentOS

    How to Change Hostname (Computer Name) on Fedora & CentOS

    By RahulFebruary 25, 20233 Mins Read

    Brief: This article describes to how to find the current hostname of the system. Also, how can you change the hostname of your Redhat-based systems?

    Advertisement

    Changing the hostname permanently on Fedora and CentOS is a simple process that requires editing a few system files. In this article, we will show you how to change the hostname permanently on Fedora and CentOS.

    Step 1: Check the current hostname

    Before changing the hostname, it’s a good idea to check the current hostname of your Fedora or CentOS system. You can do this by opening a terminal window and running the following command:

    hostnamectl 
    

    This will display the current hostname, as well as other system information.

    Step 2: Set the new hostname

    Choose one of the below methods to change the system’s hostname permanently.

    Method 1: Using hostnamectl command

    To set the new hostname, you can use the `hostnamectl` command on Ubuntu or the hostname command on Debian. For example, to set the new hostname to “newhostname”, you can run the following command:

    sudo hostnamectl set-hostname newhostname 
    

    This will change the hostname for the current session as well as update the /etc/hostname file.

    Method 2: Editing /etc/hostname file

    To make the hostname change permanent, you need to edit the hostname file on your system. This file contains the system’s hostname, and it is read during the boot process. To edit the file, you can use your favorite text editor. For example, to edit the file using nano, you can run the following command:

    sudo nano /etc/hostname 
    

    This will open the hostname file in the nano editor. Replace the current hostname with the new hostname and save the file.

    Step 3: Edit the hosts file

    In addition to editing the hostname file, you also need to edit the hosts file on your system. This file maps IP addresses to hostnames, and it is read during the boot process. To edit the file, you can run the following command:

    sudo nano /etc/hosts 
    

    This will open the hosts file in the nano editor. Look for the line that contains the old hostname and replace it with the new hostname.

    1
    127.0.0.1    newhostname

    Save the file and exit the editor.

    Conclusion

    Changing the hostname permanently on Fedora and CentOS is a simple process that requires editing a few system files and restarting the network. By following the steps in this article, you can ensure that your new hostname survives reboots and is applied consistently across your system.

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    Understanding 2>&1 in Bash: A Beginner’s Guide

    How to Choose the Best Shebang (#!) for Your Shell Scripts

    Modulus Operator (%) in Bash

    Using Modulus Operator (%) in Bash

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • How to List Manually Installed Packages in Ubuntu & Debian
    • 10 Bash Tricks Every Developer Should Know
    • How to Validate Email Address in JavaScript
    • Firewalld: Common Firewall Rules and Commands
    • 12 Apk Commands in Alpine Linux Package Management
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.