Blog

Changing a cloud VM’s hostname

When you’re working with servers, you may run across cloud servers whose hostnames aren’t very descriptive. How about 30714-2-1290387 or domU-12-31-39-09-E5-E7 for a hostname of a server. Don’t they look like they could be a part number or a serial number of a server rather than its hostname?

Well, that’s exactly the kind of hostname many of the IaaS providers assign their cloud servers. And other than a few exceptions, you don’t have an option of picking a hostname while creating a cloud server.

Now imagine having to manage scores or more servers with similarly cryptic hostnames. It’s a tedious and frustrating thought, at best.

Given that, it’s a good thing that once the server has been created, it’s rather easy to go in and change it’s hostname. In this blog post, we will walk through how to do that for both Linux and Windows.

On Linux servers, you can call the hostname program and pass it your desired hostname.
$ hostname <desired_hostname>

However, calling hostname doesn’t make the change permanent. It’s only for the current ‘boot’ session and your new value will be reset to the old one at system reboot.

To make it permanent, on CentOS/RedHat/Amazon AMI Linux distributions, you have to make a change to the /etc/sysconfig/network file. There’s a HOSTNAME line in there which is read by the boot scripts to set the hostname at startup. Set that parameter to your desired hostname.
HOSTNAME=<desired_hostname>

On Ubuntu/Debian distributions, you have to edit the entry in the /etc/hostname file to make the hostname change permanent. In that file, the only entry will be the existing hostname of the server; replace that value with <desired_hostname>.

If you had the Halo daemon already installed and running prior to changing the hostname, you will need to restart the Halo daemon for the updated hostname to be picked up by Halo. To restart Halo, do the following:

sudo service cphalod restart
or
sudo /etc/init.d/cphalod restart

If you just edit the respective files to effect a hostname change and not run the hostname command, the change won’t take effect until the server is rebooted.

To change the hostname of Windows VMs, do the following

  1. Open System by clicking the Start button , clicking Control Panel, clicking System and Maintenance, and then clicking System.
  2. Under Computer name, domain, and workgroup settings, click Change settings.  If you are prompted for an administrator password or confirmation, type the password or provide confirmation.
  3. On the Computer Name tab, click Change.
  4. Under Computer name, delete the old computer name, type a new computer name, and then click OK. If your computer is part of a domain, you will be prompted to provide the name and password of an account with permission to rename the computer in the domain.

The Windows VMs have to be rebooted for the hostname change to take effect.

Let’s take a look at how our dashboard looks (screenshot below) after we have made a bunch of hostname changes. I would be much happier if I were looking at a dashboard like the one below rather than the one I showed you at the beginning of this blog.

In a future blog post, we will look at how to dynamically assign your desired hostnames at server creation time.

Stay up to date

Get the latest news and tips on protecting critical business assets.

Related Posts