How to Change Hostname on Ubuntu 25.10

Change hostname on Ubuntu 25.10 with hostnamectl, update /etc/hosts, preserve it through cloud-init, and verify the new name without rebooting.
A polished Ubuntu server with an orange identity glow and cyan network trails in a midnight-blue data center.

To change hostname on Ubuntu 25.10, set the system name with hostnamectl and update Ubuntu’s local name mapping. You will have a persistent, locally resolvable hostname in about five minutes, without rebooting the VPS.

Prerequisites

  • Ubuntu 25.10 (Questing Quokka) installed on the VPS.
  • An SSH session as root, or a normal user with working sudo access.
  • A new hostname such as web01 or web01.example.com, using lowercase letters, numbers, hyphens, and dots only.
  • Access to your DNS provider and the server’s public IP if other machines must resolve an FQDN. No special RAM or disk allocation is needed for this change.
  • A VPSLake Linux VPS with Ubuntu 25.10 if you need a server for the procedure.

Step 1: Record the current hostname

Check the release and each hostname type first so you can distinguish the saved name from a temporary value supplied by networking or the VPS image.

cat /etc/os-release
hostnamectl --static
hostnamectl --transient
hostnamectl --pretty
hostname

The release file should identify Ubuntu 25.10. Blank transient or pretty values are normal. A sample result may look like this:

PRETTY_NAME="Ubuntu 25.10 (Questing Quokka)"
old-node.example.com
old-node.example.com

old-node.example.com

The static hostname is the durable operating-system value you will change. The transient name can come from DHCP or metadata, while the pretty name is only an optional description.

Step 2: Set the persistent hostname

hostnamectl changes the active hostname and writes the persistent /etc/hostname value through systemd, keeping the current session and the next boot aligned.

sudo hostnamectl set-hostname NEW_HOSTNAME
hostnamectl --static
cat /etc/hostname

Replace NEW_HOSTNAME with a short name or FQDN, such as web01.example.com. Do not use spaces, underscores, or a trailing dot. Static names are limited to valid DNS-style characters and 64 characters; the systemd hostnamectl documentation explains the distinction between static, transient, and pretty hostnames.

Both checks should now print the new value, and the command normally produces no success message:

web01.example.com
web01.example.com

If you want a human-readable label in addition to the machine name, set it independently. This optional value may contain spaces and is not used for DNS:

sudo hostnamectl set-hostname "NEW_PRETTY_NAME" --pretty
hostnamectl --pretty

For example, NEW_PRETTY_NAME could be Production web server.

Step 3: Make the new name resolve locally

Changing the system name does not automatically update /etc/hosts, so local programs can still resolve the old name or return localhost until you correct that mapping.

Open the file:

sudo nano /etc/hosts

Keep the existing 127.0.0.1 localhost and IPv6 records. Replace an old 127.0.1.1 machine-name line, or add one if it is missing. For an FQDN, use this format:

127.0.1.1 NEW_HOSTNAME NEW_SHORT_NAME

For web01.example.com, the short alias is web01:

127.0.1.1 web01.example.com web01

If you chose only web01, use 127.0.1.1 web01. Keep one machine-name entry rather than leaving both the old and new lines in place. This pattern keeps the server’s own name available locally without depending on public DNS.

Test the resolver after saving the file:

getent hosts NEW_HOSTNAME
hostname --fqdn
hostname -s

For the example FQDN, successful output is similar to:

127.0.1.1       web01.example.com web01
web01.example.com
web01

The hosts file affects this VPS only. Create an A or AAAA record with your DNS provider if laptops, monitoring systems, or other servers must resolve the name.

Step 4: Prevent cloud-init from undoing the change

Some VPS images use cloud-init to apply a provider-supplied hostname during boot, so check whether it is installed before changing any cloud configuration.

if command -v cloud-init >/dev/null 2>&1; then
  cloud-init status --long
else
  echo "cloud-init is not installed"
fi

If cloud-init is absent, continue to Step 5. If it is installed and the new name remains after a reboot, no adjustment is needed. If it restores the old name, add a small drop-in that preserves the local setting:

sudo install -d -m 0755 /etc/cloud/cloud.cfg.d
printf '%s\n' 'preserve_hostname: true' | sudo tee /etc/cloud/cloud.cfg.d/99-preserve-hostname.cfg
sudo hostnamectl set-hostname NEW_HOSTNAME

The tee command should echo:

preserve_hostname: true

The cloud-init module reference documents preserve_hostname. If the provider continues to apply a hostname from instance metadata, update that provisioning value as well.

Step 5: Refresh your SSH session

The new name is active immediately, but an existing shell prompt may have been created with the old value. Confirm the live and persistent settings, then open a second SSH session.

hostname
hostnamectl --static
cat /etc/hostname

All three lines should contain the chosen hostname:

web01.example.com
web01.example.com
web01.example.com

Most applications do not need a restart for this change. Restart an individual service only when that application reads the hostname once at startup, using its actual unit name rather than guessing:

sudo systemctl restart YOUR_SERVICE

Replace YOUR_SERVICE with a real service you administer. Do not restart networking or reboot solely to apply the hostname.

Verify the new hostname

Run this final group to confirm the static name, short name, fully qualified result, and local resolver entry:

hostnamectl --static
hostname -s
hostname --fqdn
getent hosts NEW_HOSTNAME

For web01.example.com, the first three lines should be web01.example.com, web01, and web01.example.com. The last line should return the 127.0.1.1 mapping or the expected DNS address. When those values agree, Ubuntu 25.10 is using the new hostname consistently.

Troubleshooting

hostnamectl: invalid hostname

The static name contains a character Ubuntu rejects, commonly a space, underscore, or trailing dot. Use lowercase letters, numbers, hyphens, and dots in NEW_HOSTNAME; put spaces only in NEW_PRETTY_NAME. Also check that every FQDN label starts and ends with a letter or number.

hostname --fqdn still shows the old name

The active hostname changed, but /etc/hosts still contains the previous 127.0.1.1 entry or has duplicate machine-name lines. Replace the stale line, keep one mapping for the new name, and run getent hosts NEW_HOSTNAME again. If only remote systems see the old name, update public DNS and allow its cached record to expire.

The old hostname returns after reboot

Cloud-init, DHCP metadata, or the VPS image is applying a name during startup. Check cloud-init status --long, add the 99-preserve-hostname.cfg drop-in from Step 4 when cloud-init is responsible, and update the provider’s provisioning hostname if it continues to overwrite the local setting.

sudo: a password is required or Access denied

The current account lacks the privilege needed to change the system name. Run the command with sudo after authenticating, verify that sudo -v succeeds, or reconnect as root; changing permissions on /etc/hostname is not a safe workaround.

Next steps

  • Add and test the public A or AAAA record if the hostname will be used by websites, TLS, mail, or monitoring.
  • Request a matching PTR record through the system that manages your VPS IP when reverse DNS matters.
  • Update SSH inventory, backups, monitoring, certificates, and configuration-management records that still use the old name.

FAQ

Can I change the hostname while connected over SSH?

Yes. The current SSH connection normally stays open because changing the hostname does not restart the network or SSH daemon. Open a new session afterward so your shell prompt is built with the new name.

Should I use a short hostname or an FQDN?

A short name such as web01 is fine for a standalone VPS or private network. Use an FQDN when TLS, mail, monitoring, or multi-server tools need a unique identity, and make sure it resolves through /etc/hosts or public DNS.

Does this rename my VPS in the client area or update reverse DNS?

No. hostnamectl changes Ubuntu’s local operating-system identity only. The VPS label, public DNS record, and PTR record are separate settings managed in their respective systems.

What is the difference between a static and pretty hostname?

The static hostname is the operational name stored in /etc/hostname and used by system services. A pretty hostname is an optional human-readable label that can contain spaces; it does not replace the static name or publish DNS.

Samrat Ghosh
Written by

Samrat Ghosh

Founder & Infrastructure Engineer

Samrat Ghosh is the founder of VPSLake, where he builds and runs the remote desktop and VPS hosting infrastructure the company is built on. He writes hands-on guides about RDP, Windows Server, VPS management and secure remote access - the practical documentation he wishes had…

Previous Article

Dedicated Server in USA: Choose Dallas, LA or Miami

Next Article

How to Change Hostname on Ubuntu 26.04 (Step-by-Step)

Write a Comment

Leave a Comment

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

Subscribe to our Newsletter

Subscribe to our email newsletter to get the latest posts delivered right to your email.
Pure inspiration, zero spam ✨