Introduction
When you deploy a new RCS 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, RCS destroys the cloud server and reinstalls a new operating system image, which wipes all the data on the server.
How to Change Hostname without Erasing the Server
- Locate your operating system from the list below.
- Follow the steps for your operating system.
- (optional) Update your DNS. This procedure does not change your DNS name. If you use DNS and need to change that name, follow the guides from your DNS host. If you use RCS DNS, you'll find our guide here.
This guide uses example names: olddog for the old name and newtricks for the new.
Change Hostname on AlmaLinux, CentOS, Fedora, Rocky Linux, and VzLinux
This section applies to:
- AlmaLinux
- CentOS 7 and later
- Fedora 31 and later
- Rocky Linux
- VzLinux
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
totrue
.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
andhostname
.$ hostnamectl Static hostname: newtricks $ hostname newtricks $ hostname -a newtricks.example.com
Change Hostname on Arch Linux
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
totrue
.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.
Change Hostname on Debian & Ubuntu
This section applies to:
- Debian GNU/Linux 9 "Stretch" and later
- Ubuntu version 16.04 and later
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
totrue
.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
andhostname
.$ hostnamectl Static hostname: newtricks $ hostname newtricks $ hostname -f newtricks.example.com
Change Hostname on Fedora CoreOS
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
andhostname
.$ hostnamectl Static hostname: newtricks $ hostname newtricks
Change Hostname on FreeBSD
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.
- Change all occurrences in /etc/rc.conf.
- Change all occurrences in /etc/hosts.
Reboot the server.
Test your change with
hostname
.$ hostname newtricks
Change Hostname on OpenBSD
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:
- Change all occurrences in /etc/myname.
- Change all occurrences in /etc/hosts.
Reboot the server.
Test your change with
hostname
.$ hostname newtricks
Change Hostname on Windows
This section applies to Windows Server 2012 and later.
How to Change the Hostname in PowerShell
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
How to Change the Hostname with the GUI
- Log in to the server via RDP.
- Navigate to the "This PC" screen and click "System properties".
- Click "Change settings" next to the current computer name.
- Click the "Change" button.
- Enter a new computer name and confirm by clicking "OK".
- Restart the server.
About Windows Hostnames
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.