Skip to content
Follow
Ubuntu Linux

How to Change Hostname in Ubuntu 24.04

Richard
Written by
Richard
Oct 10, 2021 Updated Aug 14, 2026 2 min read
How to Change Hostname in Ubuntu 24.04
How to Change Hostname in Ubuntu 24.04

Your computer’s hostname in Ubuntu 24.04 is the unique network name that helps routers and other devices identify your PC. Changing this name makes it much easier to spot your machine when you share files, set up a home server, or fix network problems.

You can update your hostname in just a few seconds using a single command in the terminal. This quick guide shows you the exact steps to give your Ubuntu 24.04 system a new name right now.

⚡ Quick Answer

You change the hostname in Ubuntu 24.04 using the `hostnamectl set-hostname NEW_HOSTNAME` command. After executing this, manually edit the `/etc/hosts` file to update the old hostname with the new one. Reboot your system for the changes to take effect.

Show the current hostname

Your Ubuntu 24.04 computer uses a network name, called a hostname, to identify itself. Checking your current Ubuntu hostname is a good first step, helping you confirm the name before making changes. The `hostname` command displays this network name. Once you know the current name, you can proceed to change it. You’ll use the `hostnamectl` command followed by your chosen new network name.

The `hostname` command shows the current network name for your Ubuntu computer. This helps confirm that the hostname change was successful.

Changing your Ubuntu 24.04 system’s hostname, your computer’s network name, is accomplished with a helpful command. This process gives your computer clear network identification. You use the `hostnamectl` command followed by the new network name you choose for your computer.

To change the hostname on Ubuntu, you’ll use the `hostnamectl` command.

For example, to change the device hostname to srv1.ubuntu.local, you will run the command below.

The `hostnamectl set-hostname` command updates the system name in the `/etc/hostname` file. This step ensures proper network identification across Ubuntu 24.04.

💻Code
/etc/hostname

The [/etc/hosts] file won't be updated automatically to match the new hostname. You might need to edit it manually to replace the old hostname with the new one.

🐧Bash / Shell
sudo nano /etc/hosts

Then, replace the old name with the new one, save the file, and exit.

💻Code
127.0.0.1 localhost
127.0.1.1 srv1.ubuntu.local

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
⚠️Warning
After changing the hostname, you may need to restart the device. Run the command below to do that.
🐧Bash / Shell
sudo reboot

When you log back in, the system should have the new name you assigned.

That should do it!

Wrapping up, updating your Ubuntu 24.04 hostname takes only a moment in the terminal.

  • Changing the hostname in Ubuntu 24.04 is a straightforward process using the hostnamectl command.
  • Always check your current hostname using hostnamectl before making changes.
  • Update both the /etc/hostname and /etc/hosts files to ensure the hostname is configured correctly.
  • Restart your device to apply the changes effectively.
  • Using clear and distinct hostnames is essential for better network management and identification of devices.

Was this guide helpful?

Was this helpful?
Richard

About the Author

Richard

Tech Writer, IT Professional

Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.

📚 Related Tutorials

How to Change Screen Brightness in Ubuntu Linux
Ubuntu Linux How to Change Screen Brightness in Ubuntu Linux
How to Edit Hosts File with PowerToys on Windows 11
Windows How to Edit Hosts File with PowerToys on Windows 11
How to Set System Locale on Ubuntu 24.04
Ubuntu Linux How to Set System Locale on Ubuntu 24.04
How to Install OpenSSL Ubuntu Manually for Latest Security
Ubuntu Linux How to Install OpenSSL Ubuntu Manually for Latest Security

No comments yet — be the first to share your thoughts!

Leave a Comment

Your email address will not be published. Required fields are marked *