How to Change Hostname in Ubuntu 24.04
Changing the hostname in Ubuntu 24.04 gives your computer a unique name on the network. This name, called a hostname, acts like a digital nickname that helps other devices find and identify your PC.
For instance, you might change a default name to something more descriptive, like ‘my-ubuntu-server’ or ‘dev-machine-02’, making it easier to manage multiple computers. A clear hostname is especially helpful when you’re troubleshooting network problems or organizing several machines.
Ubuntu 24.04 makes it straightforward to update this identifier using commands in the terminal.
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 simple 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.
/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.
sudo nano /etc/hosts
Then, replace the old name with the new one, save the file, and exit.
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
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
hostnamectlcommand. - Always check your current hostname using
hostnamectlbefore making changes. - Update both the
/etc/hostnameand/etc/hostsfiles 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?
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!