Article

Table of Contents
Theme:
Was this article helpful?
Try Vultr Today with

$50 Free on Us!

Want to contribute?

You could earn up to $300 by adding new articles!

Change Hostname on Debian

Last Updated: Wed, Apr 29, 2020
Best Practices Debian System Admin

Supported Versions

This guide applies to:

  • Debian GNU/Linux 9 "Stretch"
  • Debian GNU/Linux 10 "Buster"

Introduction

When creating a new Vultr VPS, you can set the Server Hostname before deployment. If you skip this step or decide to rename your server later, you'll discover that changing the server hostname from the Customer Portal also performs a fresh reinstall of the entire server.

Change Hostname Example Screenshot

Follow this guide if you need to change the server hostname without reinstalling.

Examples

This guide uses olddog for the old hostname and newtricks for the new hostname.

1. Check the Current Hostname

Check the hostname with hostname.

$ hostname
olddog

You can also use hostnamectl.

$ hostnamectl
   Static hostname: olddog
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 35ce0ea8e7e14d5da70beb7726f11df1
           Boot ID: 5e03561d1ea54d20b9f39d686f64d4b7
    Virtualization: qemu
  Operating System: Debian GNU/Linux 9 (stretch)
            Kernel: Linux 4.9.0-12-amd64
      Architecture: x86-64

2. Change Hostname

Change the hostname to newtricks.

$ sudo hostnamectl set-hostname newtricks

3. Update /etc/hosts

Use your favorite text editor to change any instances of your old hostname to the new hostname in /etc/hosts. If you have a DNS name pointed to this instance, it's a best practice to also set that name here.

$ sudo nano /etc/hosts

From:

127.0.0.1       localhost
127.0.1.1       guest.guest     guest

To:

127.0.0.1       localhost
127.0.1.1       newtricks.example.com newtricks

4. Confirm the Change

Reboot the server.

Test your change with hostnamectl and hostname.

$ hostnamectl
   Static hostname: newtricks
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 35ce0ea8e7e14d5da70beb7726f11df1
           Boot ID: 5e03561d1ea54d20b9f39d686f64d4b7
    Virtualization: qemu
  Operating System: Debian GNU/Linux 9 (stretch)
            Kernel: Linux 4.9.0-12-amd64
      Architecture: x86-64

$ hostname
newtricks
$ hostname -f
newtricks.example.com

Update DNS

Your server hostname is changed and ready to use. This procedure does not change your DNS name, and you'll need to perform those steps at your domain registrar.

Want to contribute?

You could earn up to $300 by adding new articles