When you deploy a new Vultr cloud server, you can set the Server Hostname on the deployment page. Later, if you decide to change the server name, you can use the Change Hostname form in the server's Settings menu.
However, if you use this method to change the hostname, Vultr destroys the cloud server and reinstalls a new operating system image, which wipes all the data on the server.
This guide uses example names: olddog for the old name and newtricks for the new.
This section applies to:
Procedure:
Important: Disable automatic hostname updates from cloud-init by editing /etc/cloud/cloud.cfg
.
$ sudo nano /etc/cloud/cloud.cfg
Change the value of preserve_hostname
to true
.
preserve_hostname: true
Save and exit the file.
Check the current hostname with the hostname
command.
$ hostname
olddog
You can also use hostnamectl
.
$ hostnamectl
Static hostname: olddog
Change the hostname to newtricks.
$ sudo hostnamectl set-hostname newtricks
Change any instances of the old hostname in /etc/hosts
. If you have a DNS name pointed to this instance, it's also best practice to set that name here.
$ sudo nano /etc/hosts
Example of old hosts file:
127.0.0.1 olddog
::1 olddog
Example of new hosts file.
127.0.0.1 newtricks newtricks.example.com
::1 newtricks newtricks.example.com
Reboot the server.
Test your change with hostnamectl
and hostname
.
$ hostnamectl
Static hostname: newtricks
$ hostname
newtricks
$ hostname -a
newtricks.example.com
This section applies to any recently updated version of Arch Linux.
Procedure:
Important: Disable automatic hostname updates from cloud-init by editing /etc/cloud/cloud.cfg
.
$ sudo nano /etc/cloud/cloud.cfg
Change the value of preserve_hostname
to true
.
preserve_hostname: true
Save and exit the file.
Check the current hostname using the hostnamectl
tool.
$ hostnamectl
Static hostname: olddog
Check the hosts file with the getent
tool.
$ getent hosts
127.0.0.1 localhost
127.0.0.1 localhost
127.0.1.1 olddog.localdomain olddog
Change the hostname to newtricks.
$ sudo hostnamectl set-hostname newtricks
Change any instances of the old hostname in /etc/hosts
. If you have a DNS name pointed to this instance, it's also best practice to set that name here.
$ sudo vim /etc/hosts
Example of old hosts file:
127.0.0.1 localhost
::1 localhost
127.0.1.1 olddog.localdomain olddog
Example of new hosts file:
127.0.0.1 localhost
::1 localhost
127.0.1.1 newtricks.localdomain newtricks
Either reboot the server or log out and back in again to your user session.
Test the change with the hostnamectl
tool.
$ hostnamectl
Static hostname: newtricks
Test the change with the getent
tool.
$ getent hosts
127.0.0.1 localhost
127.0.0.1 localhost
127.0.1.1 newtricks.localdomain newtricks
îçµ± Note: For a system with a permanent IP address, that permanent IP address should be used instead of 127.0.1.1. The order of hostnames in /etc/hosts is significant. The first string is the canonical hostname. Subsequent names on the same line are aliases.
This section applies to:
Procedure:
Important: Disable automatic hostname updates from cloud-init by editing /etc/cloud/cloud.cfg
.
$ sudo nano /etc/cloud/cloud.cfg
Change the value of preserve_hostname
to true
.
preserve_hostname: true
Save and exit the file.
Check the current hostname with the hostname
command.
$ hostname
olddog
You can also use hostnamectl
.
$ hostnamectl
Static hostname: olddog
Change the hostname to newtricks.
$ sudo hostnamectl set-hostname newtricks
Change any instances of the old hostname in /etc/hosts
. If you have a DNS name pointed to this instance, it's also best practice to set that name here.
$ sudo nano /etc/hosts
Example of old hosts file:
127.0.0.1 localhost
127.0.1.1 olddog
Example of new hosts file.
127.0.0.1 localhost
127.0.1.1 newtricks.example.com newtricks
Reboot the server.
Test your change with hostnamectl
and hostname
.
$ hostnamectl
Static hostname: newtricks
$ hostname
newtricks
$ hostname -f
newtricks.example.com
Fedora CoreOS (FCOS) uses the Ignition file to set the server hostname. If you decide to rename a running server, you'll need to update the name from the command line.
Connect to your FCOS instance and change to the root user.
$ sudo su - root
Check the hostname with hostname
.
# hostname
olddog
You can also use hostnamectl
.
# hostnamectl
Static hostname: olddog
Change the hostname to newtricks.
# hostnamectl set-hostname newtricks
Reboot the server.
# reboot
Test your change with hostnamectl
and hostname
.
$ hostnamectl
Static hostname: newtricks
$ hostname
newtricks
This section applies to all versions of FreeBSD.
Procedure:
Check the current hostname with the hostname
command.
$ hostname
olddog
Change the hostname to newtricks using a text editor.
Reboot the server.
Test your change with hostname
.
$ hostname
newtricks
This section applies to all versions of OpenBSD.
Procedure:
Check the current hostname with the hostname
command.
$ hostname
olddog
Change the hostname to newtricks using a text editor:
Reboot the server.
Test your change with hostname
.
$ hostname
newtricks
This section applies to Windows Server 2012 and later.
Open an elevated PowerShell. If you are in standard PowerShell, elevate your access as shown:
PS C:\> Start-Process PowerShell -Verb Runas
Check the hostname with $env:computername
.
PS C:\> $env:computername
OLDDOG
Change the hostname to NEWTRICKS. Using the -Restart parameter will also immediately restart the server. Full documentation on the Rename-Computer cmdlet is available at Microsoft.
PS C:\> Rename-Computer -NewName "NEWTRICKS" -Restart
Verify the hostname has changed with $env:computername
.
PS C:\> $env:computername
NEWTRICKS
A hostname is what identifies a server. Most Windows Server users name their servers with the hostname consisting of two parts: role.domain
. The role
part is the role installed on the server, followed by the number. For example, if dc01
is the first server that acts as a DC in this particular network, Windows makes this an FQDN by putting the Active Directory domain as the domain
part. For example, if this is the third web server in this network, and the domain is example.com
, the hostname would be:
ws03.example.com
Note that changing the hostname on Windows Server may conflict with some installed roles. Changing the hostname before installing roles on the server is a good idea. For recovery purposes, make a snapshot first if you decide to change the hostname on a Windows Server.