Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
FREEDOM251

Freedom251 › Blog › Cloud Computing

How to Find and Change Your Hostname in Ubuntu 22.04, 24.04, and Later

By Freedom251 Team · · 3 min read

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

On a standard Ubuntu installation, run hostnamectl to see the system’s hostname and sudo hostnamectl set-hostname web-node-1 to change it. Replace web-node-1 with your chosen name, then run hostnamectl again to verify. The change normally persists across reboots on a conventional local system; cloud instances may be configured to replace it.

Find the current hostname

Open a terminal and run:

hostnamectl

The status output shows hostname information, including the static, transient, and pretty names when available. To print the hostname currently active in the kernel, run:

As an Amazon Associate I earn from qualifying purchases.

hostname

To display one specific systemd hostname type, use hostnamectl --static, hostnamectl --transient, or hostnamectl --pretty. The hostnamectl command with no subcommand displays status. These options are documented in the Ubuntu Noble hostnamectl manual.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Change the hostname

  1. Choose a simple name, such as web-node-1. Lowercase ASCII letters, digits, and hyphens are a safe choice; avoid spaces for a standard machine name.

  2. Set the name with administrator privileges:

    sudo hostnamectl set-hostname web-node-1

    Replace the example with your chosen name. On modern Ubuntu, this default command changes the pretty, static, and transient hostname values together. Use --static, --transient, or --pretty with set-hostname when you specifically want to change only one type.

  3. Verify the result:

    hostnamectl

    You can also run hostname to check the active kernel hostname.

Ubuntu’s Noble manual documents these commands for systemd 255.4-1ubuntu8.17. Jammy-era documentation describes the same general hostname-type behavior; on unusually customized or older installations, consult the local hostnamectl manual for supported options.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose a valid system hostname

Systemd distinguishes three hostname types:

Static and transient hostnames follow DNS-style naming rules and are limited to 64 characters. A single label such as web-node-1 is a straightforward choice for the system hostname; dots can be used when configuring a valid fully qualified domain name. The Ubuntu hostname configuration manual recommends a single label in /etc/hostname.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When the default hostnamectl set-hostname command sets multiple types, systemd simplifies the value for static and transient use by removing characters those types do not allow. Entering a DNS-compatible name avoids surprises from that cleanup.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Will the hostname change survive a reboot?

On a conventional Ubuntu installation, hostnamectl set-hostname updates the static hostname kept in /etc/hostname; systemd applies that configured name at boot. A transient name can instead come from network configuration when no static hostname is set. The change will ordinarily remain after reboot unless a higher-priority provisioning or network configuration overrides it.

If the name changes back, first determine whether the machine is managed by cloud-init or another provider-specific setup. Cloud-init’s preserve_hostname setting controls whether it changes the hostname, and its configuration can also rewrite /etc/hosts at boot. See the cloud-init module reference and check the instance’s provisioning configuration.

Google Compute Engine exception

On Google Compute Engine images using Ubuntu 24.04 LTS or later, Ubuntu documents a specific exception: /etc/hostname is absent by default and cloud-init’s create_hostname_file key is false. In this setup, setting the name through the hostname command can change it only temporarily, and Google DHCP may overwrite it. Use the cloud-init or provider mechanism appropriate to the instance, then verify the result after reboot. This behavior is specific to the documented GCE images, not all Ubuntu 24.04 systems. See Ubuntu’s GCE hostname guidance.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Hostname, FQDN, and /etc/hosts are different

Changing the system hostname does not by itself configure a fully qualified domain name (FQDN). An FQDN is resolver-derived and depends on name-service configuration. Results can be unsuitable on systems with multiple network interfaces or mobile network environments, as the Ubuntu hostname and FQDN manual explains.

The /etc/hosts file is a separate local mapping between IP addresses and canonical hostnames or aliases. If you need a local mapping for the new name, review existing entries before editing them, especially if services or scripts still refer to the old name. The Ubuntu hosts manual describes this file’s format.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Cloud ComputingHostnameLinuxsystem administrationUbuntu

Leave a Reply

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

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.