How to Change VPS Hostname in Linux? [Ubuntu, CentOS, Debian]

Whether you’re running Ubuntu or other Linux distributions, this guide will walk you through everything you need to know about how to change VPS hostname Linux.

Updated: 16 Aug, 25 by Susith Nonis 8 Min

List of content you will read in this article:

A hostname might seem like a small detail, but it plays a big role in how your server interacts within a network and with external services. For VPS users, system administrators, and IT students, understanding how to properly configure and manage hostnames is essential. Whether you’re running Ubuntu, CentOS, Debian, or other Linux distributions, this guide will walk you through everything you need to know about how to change VPS hostname Linux — from checking your current hostname to making persistent hostname changes that survive reboots.

If you’re new to VPS, we recommend starting with our beginner’s guide on How to Setup VPS to get comfortable with basic configurations.

 

A hostname is the unique label assigned to a device (or server) on a network. It’s how systems identify each other when communicating. For VPS hosting, the hostname often shows up in SSH sessions, email headers, monitoring dashboards, and network configurations.

For example, instead of remembering an IP address like 192.168.0.12, you can refer to your server as webserver01.

Why does it matter?

  • Server management: Easily identify different VPS servers you own or manage.
  • Networking: Smooth communication between devices within your infrastructure.
  • Email delivery: Mail servers validate hostnames for spam protection — a misconfigured hostname can cause email rejection.
  • Branding & trust: A properly set Fully Qualified Domain Name (FQDN) adds professionalism.

If you’d like a broader introduction, check out our detailed article on How to Set or Change Hostname in Linux.

 

Before you change VPS hostname Linux, it’s best to know your server’s current hostname.

Using the hostname command

hostname

This prints the short hostname of your server.

Using the hostnamectl command

For systemd-based distributions (Ubuntu 16.04+, CentOS 7+, Debian 9+), you can run:

hostnamectl

This displays:

  • Static hostname
  • Transient hostname
  • Chassis, machine ID, and OS information

Using /etc/hostname

You can also view the hostname stored in the system file:

cat /etc/hostname

 

Different Linux distributions have slightly different ways to set a new hostname. Below we’ll go step by step for the most common ones.

Ubuntu & Debian

Ubuntu and Debian use systemd, which makes changing hostnames straightforward.

1. Set hostname Ubuntu VPS with hostnamectl

sudo hostnamectl set-hostname your-new-hostname

Example:

sudo hostnamectl set-hostname webserver01

2. Update /etc/hosts

sudo nano /etc/hosts

Find the line with 127.0.0.1 and update it:

127.0.0.1   localhost webserver01

3. Verify the change

hostnamectl

You should see your new hostname.

💡 Pro Tip: If your VPS hostname not changing after reboot, make sure you’ve updated /etc/hostname as well:

echo "webserver01" | sudo tee /etc/hostname

If you’re setting up Ubuntu for the first time, you may also find our guide on How to Setup Domain on VPS useful, since domain configuration often works hand-in-hand with hostnames.

 

CentOS & RHEL

For CentOS/RHEL, the process is similar but may involve nmcli (Network Manager).

1. Check the hostname

hostnamectl status

2. Change hostname with hostnamectl

sudo hostnamectl set-hostname centos-server01

3. Update /etc/hosts

sudo nano /etc/hosts

Add the new hostname alongside 127.0.0.1.

4. Verify

hostname

If you’re using CentOS 6 (older versions), you’ll need to edit /etc/sysconfig/network instead:

sudo nano /etc/sysconfig/network

Change or add:

HOSTNAME=centos-server01

 

Other Distros (Alpine, Arch)

For lightweight distributions, the process is manual.

Alpine Linux:

Edit /etc/hostname:

sudo nano /etc/hostname

Replace the old hostname with the new one, then run:

/etc/init.d/hostname restart

Arch Linux:

sudo hostnamectl set-hostname arch-node01

And don’t forget to update /etc/hosts.

 

One of the biggest mistakes beginners make is updating the hostname temporarily but forgetting persistence. This results in VPS hostname not changing permanently or reverting after a reboot.

Editing /etc/hostname

Add your new hostname here:

echo "myserver01" | sudo tee /etc/hostname

 

Updating /etc/hosts

Make sure the new hostname is reflected:

127.0.0.1   localhost myserver01

 

Reboot & Verify

sudo reboot

After logging back in:

hostnamectl

If the VPS hostname not changing after reboot, your VPS might be using cloud-init, which overrides settings. To fix:

sudo nano /etc/cloud/cloud.cfg

Find:

preserve_hostname: false

Change it to:

preserve_hostname: true

Save and reboot.

This ensures persistent hostname change even in cloud environments.

 

When configuring Linux servers, you’ll often see references to both hostname and FQDN (Fully Qualified Domain Name). While they’re related, they’re not the same thing.

  • Hostname: The short label of the server (e.g., server1).
  • Domain Name: The registered domain you own (e.g., example.com).
  • FQDN: The full path that uniquely identifies your server on the internet (e.g., server1.example.com).

Think of it like this: the hostname is the nickname of your server on the local network, while the FQDN is its full postal address on the internet.

Why is Linux change FQDN important?

  • Email Servers: Postfix, Sendmail, and Exim often require a valid FQDN to avoid being flagged as spam.
  • DNS Resolution: Services depend on mapping hostnames to IP addresses.
  • Professionalism: Instead of ubuntu-vps, your server could appear as mail.mydomain.com.

If you want to configure your VPS beyond hostnames and link it with your domain, we recommend our guide on How to Setup Domain on VPS.

 

Even after following the steps above, some users encounter issues with hostname persistence or functionality. Let’s go over common problems.

1. VPS hostname not changing after reboot

Cause: Only the transient hostname was set, or cloud-init reset the hostname.
Solution:

  • Update /etc/hostname
  • Update /etc/hosts
  • Modify /etc/cloud/cloud.cfg with preserve_hostname: true

2. Mail servers rejecting connections

Cause: The mail server requires an FQDN, but only a short hostname is configured.
Solution for Linux change FQDN:

  • Set FQDN using:

sudo hostnamectl set-hostname mail.example.com

  • Ensure /etc/hosts contains:

127.0.0.1   localhost mail.example.com mail

3. SSH still showing old hostname

Cause: Your SSH session doesn’t refresh automatically.
Solution: Log out and reconnect. Use:

uname -n

to confirm.

4. Hostname mismatch in logs

Cause: Some applications store the old hostname.
Solution: Restart related services (Apache, Postfix, MySQL) after hostname updates.

5. Persistent hostname change not working on CentOS

Cause: /etc/sysconfig/network not updated.
Solution: Add or modify the line:

HOSTNAME=new-hostname

By applying these fixes, you ensure a stable persistent hostname change across all reboots and services.

 

Learning how to change VPS hostname Linux is a crucial skill for anyone managing servers. Whether you’re a DevOps beginner, a system administrator, or an IT student, a properly configured hostname helps with:

  • Server identification
  • DNS and networking consistency
  • Mail server reputation
  • Better server management

By following the steps for Ubuntu, Debian, CentOS, RHEL, and other distros, and ensuring persistent hostname change, you’ll avoid common pitfalls such as hostname reverting after reboot or mail server misconfigurations.

If you’re ready to take full control of your hosting environment, explore our VPS Server plans and enjoy reliable performance with complete administrative freedom.

 

Run: sudo hostnamectl set-hostname your-new-hostname Then update /etc/hosts and /etc/hostname. This ensures persistent hostname change.

This usually happens because /etc/hostname wasn’t updated or cloud-init overwrote the change. Edit /etc/cloud/cloud.cfg and set preserve_hostname: true.

A hostname is the system name (e.g., server1). An FQDN includes the full domain path (e.g., server1.example.com).

Not always. With hostnamectl, the change applies instantly. However, some applications (like mail servers) may require a restart.

Yes. Ubuntu installer prompts for a hostname. You can later use hostnamectl to update it if needed.

Yes, but you should update /etc/hosts and restart dependent services to avoid disruptions.

Susith Nonis

Susith Nonis

I'm fascinated by the IT world and how the 1's and 0's work. While I venture into the world of Technology, I try to share what I know in the simplest way with you. Not a fan of coffee, a travel addict, and a self-accredited 'master chef'.

user monovm

German Beahan

2024, Dec, 24

Great post! You've provided a clear and detailed guide on changing a VPS hostname, which is super helpful for anyone managing a VPS. I appreciate how you broke down the process for different operating systems, making it accessible for users with varying tech knowledge. Understanding hostnames is crucial for efficient network management, and your step-by-step instructions simplify it beautifully. This will definitely aid many in personalizing their servers and improving system management. Thanks for sharing!

user monovm

Mrs. Dulce Bergstrom III

2025, Aug, 25

This is a fantastic post for anyone looking to understand and manage their VPS hostname! You've clearly explained the basics and the importance of having a unique hostname for server identification, which is crucial for network management. The step-by-step instructions for both Windows and Linux are super helpful, making it easy to follow along. Thanks for sharing such valuable information—it's definitely a go-to guide for anyone diving into VPS setups!