UbuntuUbuntu Based

How To Change Hostname on Ubuntu 24.04 LTS

Change Hostname on Ubuntu 24.04

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.

    1. Open the Settings app from the application menu or by pressing Super + I.
    2. Navigate to the “About” section.
    3. Click on the “Device Name” field and enter your new hostname.
    4. Click “Apply” to save the changes.

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 hostname
    • hostnamectl: Shows the static, transient, and pretty hostnames
    • cat /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.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button