This guide applies to:
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.
Follow this guide if you need to change the server hostname without reinstalling.
This guide uses olddog for the old hostname and newtricks for the new hostname.
Check the hostname with
$ hostname olddog
You can also use
$ hostnamectl Static hostname: olddog Icon name: computer-vm Chassis: vm Machine ID: 00c6efc1008d46aabeed06a3b8a459ec Boot ID: 539da7ee88a1499db77d3ef8b82b7a72 Virtualization: kvm Operating System: Ubuntu 20.04 LTS Kernel: Linux 5.4.0-26-generic Architecture: x86-64
Change the hostname to newtricks.
$ sudo hostnamectl set-hostname newtricks
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
127.0.0.1 localhost 127.0.1.1 olddog
127.0.0.1 localhost 127.0.1.1 newtricks.example.com newtricks
Reboot the server.
Test your change with
$ hostnamectl Static hostname: newtricks Icon name: computer-vm Chassis: vm Machine ID: 00c6efc1008d46aabeed06a3b8a459ec Boot ID: 539da7ee88a1499db77d3ef8b82b7a72 Virtualization: kvm Operating System: Ubuntu 20.04 LTS Kernel: Linux 5.4.0-26-generic Architecture: x86-64 $ hostname newtricks $ hostname -f newtricks.example.com
Note: If you deployed one of Vultr's standard images, you can stop here. Our standard images do not need this update because they do not have cloud-init installed.
If you installed from your own Ubuntu ISO, you might have cloud-init installed. The cloud-init service may override your hostname on the next reboot. To correct this, edit the
/etc/cloud/cloud.cfg file on your server instance. If cloud.cfg doesn't exist, then cloud-init is not installed; you do not need to create it.
$ sudo nano /etc/cloud/cloud.cfg
Add the following string to the bottom of /etc/cloud/cloud.cfg.
Save and exit the file. Reboot the server and verify the hostname is set correctly.
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.