How To Change Hostname on Ubuntu 24.04 LTS
In this tutorial, we will show you how to change the Hostname on Ubuntu 24.04 LTS. A hostname is a label assigned to a device on a network that uniquely identifies it. In Ubuntu, there are three types of hostnames: static, transient, and pretty. The static hostname is set in the /etc/hostname
file and remains constant across reboots. The transient hostname is a dynamic hostname that can change during runtime. Lastly, the pretty hostname is a user-friendly name that can contain spaces and special characters, used for display purposes.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you the step-by-step installation of the Hostname on Ubuntu 24.04 (Noble Numbat). You can follow the same instructions for Ubuntu 22.04 and any other Debian-based distribution like Linux Mint, Elementary OS, Pop!_OS, and more as well.
Prerequisites
- A server running one of the following operating systems: Ubuntu and any other Debian-based distribution like Linux Mint.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- Basic familiarity with the command line interface.
- SSH access to the server (or just open Terminal if you’re on a desktop).
- An active internet connection.
- An Ubuntu 24.04 system with root access or a user with sudo privileges.
Change Hostname on Ubuntu 24.04
Step 1. Preparing to Change Your Hostname.
Before changing your hostname, it’s essential to check your current settings. Open a terminal and run:
hostnamectl
This command displays your current hostname and related settings. Ensure you have root or sudo access, as changing the hostname requires administrative privileges. It’s also wise to back up important files to prevent data loss during the process.
Step 2. Change Hostname in Ubuntu 24.04 LTS.
- Using the hostnamectl Command
The hostnamectl
command is the recommended method to change the hostname in Ubuntu 24.04 LTS. It allows you to modify the static, transient, and pretty hostnames. Here’s how to use it:
sudo hostnamectl set-hostname new_hostname
To change the pretty hostname, use the command:
sudo hostnamectl set-hostname "New Pretty Hostname" --pretty
Verify the changes by running: hostnamectl
- Editing System Files Manually
Another method to change the hostname is by manually editing the relevant system files. This method is useful when you need granular control over the hostname configuration. However, it’s important to exercise caution while editing system files.
Open the /etc/hostname
file with a text editor:
sudo nano /etc/hostname
Replace the current hostname with your desired hostname and save the file.
Next, update the /etc/hosts
file to reflect the new hostname:
sudo nano /etc/hosts
Save the file and exit the text editor.
- Using the hostname Command
The hostname command is a simpler way to change the hostname, but it has limitations. It only sets the transient hostname and does not persist across reboots. Here’s how to use it:
sudo hostname new_hostname
Verify the change by running: hostname
Note that this method is not recommended for permanent hostname changes, as it does not update the /etc/hostname
file.
- GUI Method
For users who prefer a graphical interface, Ubuntu Desktop provides a convenient way to change the hostname through the Settings app.
-
- Open the Settings app from the application menu or by pressing
Super
+I
. - Navigate to the “About” section.
- Click on the “Device Name” field and enter your new hostname.
- Click “Apply” to save the changes.
- Open the Settings app from the application menu or by pressing
The GUI method is user-friendly but may not be available on server installations or minimal setups.
Step 3. Verifying Hostname Changes.
After changing your hostname, it’s crucial to verify that the changes have taken effect correctly. You can use several commands to check the new hostname:
-
hostname
: Displays the current transient hostnamehostnamectl
: Shows the static, transient, and pretty hostnamescat /etc/hostname
: Displays the contents of the /etc/hostname file
If the new hostname is not reflected in all the commands’ outputs, you may need to reboot your system or investigate further.
Congratulations! You have successfully changed your Hostname. Thanks for using this tutorial to change the Hostname on the Ubuntu 24.04 LTS system. For additional help or useful information, we recommend you check the official Ubuntu website.