Menu
User

DropVPS Team

Writer: Cooper Reagan

Change Hostname in Linux Easily and Quickly

Change Hostname in Linux Easily and Quickly

Publication Date

12/26/2025

Category

Articles

Reading Time

3 Min

Table of Contents

Changing the hostname on a Linux server is a common task, especially after deploying a new VPS or cloning an existing system. A clean and correct hostname helps with server identification, monitoring, and management—particularly in multi-server environments like those used on dropvps

Step 1: Check the Current Hostname

Before changing anything, verify the current hostname.

hostnamectl

You’ll see output similar to:

Static hostname: old-hostname

Use hostnamectl, which works on most modern Linux distributions (Ubuntu, Debian, CentOS, Rocky, AlmaLinux).

sudo hostnamectl set-hostname new-hostname

Example:

sudo hostnamectl set-hostname dropvps-node-01

This change is persistent and does not require a reboot.

Step 3: Update /etc/hosts (Important)

If you skip this step, some services may fail or show warnings.

Open the hosts file:

sudo nano /etc/hosts

Update or add this line:

127.0.1.1   new-hostname

Example:

127.0.1.1   dropvps-node-01

Save and exit.

Step 4: Verify the Change

Confirm that the hostname is updated correctly:

hostname

And again:

hostnamectl status

Both commands should return the new hostname.

Step 5: Apply the Change to the Current Session

If your shell prompt still shows the old hostname, reload the session:

exec bash

Or simply reconnect via SSH.

Step 6: Reboot (Only If Needed)

A reboot is not required, but some legacy services may still cache the old hostname.

sudo reboot

Notes for VPS and Production Servers

  • Always set the hostname immediately after VPS creation

  • Avoid underscores (_) in hostnames

  • Use lowercase letters, numbers, and hyphens only

  • Match the hostname with your server role (e.g., web-01, db-01)

If you're managing multiple servers, you may also want to read:

  • How to Secure a Linux VPS After Deployment

  • Initial Server Setup Checklist for New VPS

  • How to Manage Multiple Linux Servers Efficiently

Extra: Change Hostname on Older Systems (Legacy)

If hostnamectl is not available:

sudo hostname new-hostname

Then edit:

sudo nano /etc/hostname

Replace the old hostname with the new one and reboot.That’s it. The hostname is now updated cleanly and correctly—ready for production use on your dropvps server.

🚀 Ready to Launch Your Linux Server? Set the hostname, secure your system, and get started today.👉 Get Your Linux VPS 

Linux VPS
U
Loading...

Related Posts