Skip to content

How to Change Hostname in Ubuntu 24.04

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

You change your Ubuntu 24.04 hostname to give your computer a unique network identifier.

Your hostname acts like a nickname for your PC on the network, helping other devices recognize it. This is essential for managing multiple machines or troubleshooting network issues.

For example, you might rename a server from a generic default to something specific like ‘webserver-prod-01’ for clarity.

On Ubuntu 24.04, you can efficiently update this name using the command line.

⚡ 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 has a name, called a hostname, that identifies it on a network.

💻Code
hostnamectl

This should display text similar to the lines below and a hostname for your Ubuntu computer.

💻Code
 Static hostname: srv1.ubuntu.local
Icon name: computer-vm
Chassis: vm 🖴
Machine ID: f95989a019994920b26e3b317b0d3f27
Boot ID: 3c115a8be03d4a0194ca6cd9fe488e2d
Virtualization: vmware
Operating System: Ubuntu 24.04.2 LTS
Kernel: Linux 6.11.0-19-generic
Architecture: x86-64
Hardware Vendor: VMware, Inc.
Hardware Model: VMware Virtual Platform
Firmware Version: 6.00
Firmware Date: Thu 2020-11-12
Firmware Age: 4y 4month 1w 1d

Change the hostname

Changing your hostname in Ubuntu 24.04 is straightforward using a simple command.

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.

🐧Bash / Shell
sudo hostnamectl set-hostname srv1.ubuntu.local

This command updates the primary system name in the [/etc/hostsname] file to reflect the new name.

💻Code
/etc/hostname

The [/etc/hosts] file won’t be updated automatically to match the new hostname. You might need to edit it yourself 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

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!

Conclusion:

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

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

Leave a Comment

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

Exit mobile version