Close Menu
    X (Twitter)
    Hectic GeekHectic Geek
    • Apps
      • Apps for Mac
      • Apps for PCs
      • Best Apps
    • Concepts
      • Comparison
      • For Geeks
      • IT Careers
    • Gadgets
      • Accessories
      • Best Work Laptops
      • Budget Laptops
    • GNU/Linux
      • Ubuntu
    • How To
      • Virtualization
      • Windows
      • Windows How-To
    Hectic GeekHectic Geek
    Home » How To Change Linux Hostname (Ubuntu, CentOS & more)
    GNU/Linux

    How To Change Linux Hostname (Ubuntu, CentOS & more)

    Zunaid AliBy Zunaid AliMay 13, 2022Updated:January 3, 20231 Comment4 Mins Read
    Twitter Reddit Telegram WhatsApp Email
    Ubuntu Linux As Best Distro
    Share
    Twitter Reddit Telegram WhatsApp Email

    A Linux hostname is a unique name that identifies a computer on a network. When working on multiple computers on the same network, you may get confused because of duplicate hostnames. So the need to change your hostname arises.

    Contents

    • Method 1: Change hostname using hostnamectl command
    • Method 2: Changing hostname by editing /etc/hostname
    • Method 3: Change hostname using the GUI

    In this article, we cover the best methods (including terminal and GUI) on how to change Linux hostname in some of the major Linux distributions.

    Let’s get started.

    Change hostname on Ubuntu

    First, let’s see how to check your hostname. You can choose either the hostname or hostnamectl command to check your hostname. Type any of the two commands in your terminal, and you should be able to see your current hostname.

    Checking The Name
    Checking your hostname on Ubuntu

    In this example, our hostname is rustypc. Let’s change it to hecticgeek.

    Method 1: Change hostname using hostnamectl command

    Here’s the syntax if you choose to change the hostname in the Linux terminal.

    sudo hostnamectl set-hostname hecticgeek
    Change Host Name In Linux Ubuntu
    hostname changed using the hostnamectl command

    There’s another step to this method. We need to tweak the /etc/hosts file to reflect this change.

    Open the file in your terminal with this command

    sudo nano /etc/hosts
    In Host File

    Now change it to the new hostname.

    After Changing The Name

    Save and exit nano. You’re done.

    Method 2: Changing hostname by editing /etc/hostname

    This method is similar to the second step in Method 1. Open your terminal and type the below command.

    sudo nano /etc/hostname

    You will see the current hostname, in our case hecticgeek.

    Now edit the name and put your new hostname. Save and exit.

    Save The Host File

    You can check whether it worked or not by using the hostname or hostnamectl command again. Close and re-open your terminal and type the commands.

    Rechedk The Host Name

    Hostname changed to geek

    Method 3: Change hostname using the GUI

    This method is quite easy and needs only a couple of button clicks. If you’re not good with the terminal, this method is perfect for you.

    First, go to settings. You can find it in the dropdown menu on top. Alternatively, you can go to All applications and type settings in the search bar.

    Settings In Linux

    Open settings and go to About on the left side. Now go to Device Name.

    Host Name Change In Linux GUI

    Type in your new hostname and press Rename.

    GUI Host Name In Linux

    You can re-check if it worked, from your terminal.

    Change hostname on CentOS

    You can change the hostname on CentOS using the nmcli command.

    First, check your current hostname with this command.

    sudo nmcli general hostname

    To change the hostname, just type this command

    sudo nmcli general hostname hecticgeek

    Finally, use this command to restart the systemd-hostnamed service.

    sudo systemctl restart systemd-hostnamed

    Your changes will now take effect. Use the hostnamectl command to check it.

    Change hostname on Debian

    You can use the hostname command to change your hostname. Open your terminal and type hostname then your preferred name.

    hostname hecticgeek

    You can check your new hostname by using the hostname command again.

    Why should you change your Linux hostname?

    There are a few reasons why you might need to change the hostname on Linux. The most common reason is when you change the network configuration of your computer. For example, if you change your computer’s IP address, you will need to change the hostname so that other computers on the network can still identify your machine.

    By changing your hostname to something that can be remembered easily, you can avoid many hassles. For example, the name hostingserver is much better than server2. This way, you know which device you’re currently operating on.

    Another reason you might need to change the hostname is when you have multiple computers on the same network and you want to give each one a unique name.

    Conclusion

    In this guide, we’ve demonstrated some of the methods you can follow to change your hostname on Linux. We’ve covered some of the major distros.

    Now then, which method do you think is the best for changing your hostname on Linux? Let us know in the comments.

    Linux Tips Ubuntu
    Share. Twitter Reddit Telegram WhatsApp Email
    Zunaid Ali
    • Website

    Zunaid Ali writes for businesses that breathe Technology. His tech tutorials have helped thousands understand the use of tech for a better life. He loves to code and learn new technologies.

    Related Posts

    AlmaLinux vs Ubuntu – How to Select the Best One?

    October 22, 2023

    AlmaLinux vs Rocky Linux: What you need to know

    August 24, 2023

    Pop!_OS VS Linux Mint, Which One to Select in 2023

    July 27, 2023

    Debian vs Ubuntu Server: A Brief Comparison for Beginners

    July 2, 2023

    CPU Based Simple System Stability and Benchmark Tester for Ubuntu Linux – systester

    June 16, 2023

    Top Linux Distros for Web Development in 2023

    May 20, 2023

    1 Comment

    1. Osman Biswas on May 13, 2022 1:48 pm

      Very fruitful article. Easy to understand with those image. Go on guys

      Reply

    Leave A Reply Cancel Reply

    This site uses Akismet to reduce spam. Learn how your comment data is processed.

    Latest Posts

    [Fixed] HDMI No Signal to TV or Monitor on Windows 10/11

    November 7, 2023

    AlmaLinux vs Ubuntu – How to Select the Best One?

    October 22, 2023

    Why Does My Gaming Laptop’s Battery Drain So Fast? The Science Behind It

    October 9, 2023

    Top 10 Best email Encrypting Software for Business and Personal Use

    October 7, 2023

    7 Essential Features A Learning Management System Should Include

    October 2, 2023

    The Importance of DNS for Mac Users: Why You Need to Know How It Works

    September 25, 2023

    Subscribe to Updates

    Get the latest news and updates from Hectic Geek. We won't overload you or sell your data!

    Contact
    • About Us
    • Contact Us
    • Privacy Policy
    • Write for Us
    X (Twitter)
    © 2023 Hectic Geek.

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