How to set or update VM hostname in AWS / OpenStack / DigitalOcean

How to change instance / VM hostname in AWS / OpenStack / DigitalOcean Cloud platform. When creating an instance in the AWS or OpenStack cloud, the host name is generated based on the name provided and the virtualized environment in which it runs. For AWS, a private IP address is usually used as part of the assigned host name.

In this guide, we will see how to change the instance or VM hostname for a persistent restart. Please follow these steps to change or set the instance / VM hostname in AWS, OpenStack and DigitalOcean cloud environments.

Step 1: Set VM hostname in AWS / OpenStack / DigitalOcean

I am doing this in a system using Systemd, so the hostnamectl command can be used for this purpose.

This is my current hostname:

$ hostnamectl 
   Static hostname: fed31.novalocal
         Icon name: computer-vm
           Chassis: vm
        Machine ID: d3ae97713a95466da1ef656ee2bb8456
           Boot ID: b8a8cfa70d78455b835269c88216c0a0
    Virtualization: kvm
  Operating System: Fedora 31 (Cloud Edition)
       CPE OS Name: cpe:/o:fedoraproject:fedora:31
            Kernel: Linux 5.3.7-301.fc31.x86_64
      Architecture: x86-64

I changed the hostname from fed31.novalocal to fed31.computingforgeeks.com

sudo hostnamectl set-hostname fed31.computingforgeeks.com

Let’s confirm a new host name.

$ hostnamectl 
   Static hostname: fed31.computingforgeeks.com
         Icon name: computer-vm
           Chassis: vm
        Machine ID: d3ae97713a95466da1ef656ee2bb8456
           Boot ID: b8a8cfa70d78455b835269c88216c0a0
    Virtualization: kvm
  Operating System: Fedora 31 (Cloud Edition)
       CPE OS Name: cpe:/o:fedoraproject:fedora:31
            Kernel: Linux 5.3.7-301.fc31.x86_64
      Architecture: x86-64

$ cat /etc/hostname 
fed31.computingforgeeks.com

Step 2: Modify Cloud-init configuration

If the server is rebooted, the host name is reset to the automatically generated name configured by Cloud-init. Cloud-init is an industry standard multi-distribution method for cross-platform cloud instance initialization.

Open the /etc/cloud/cloud.cfg file for editing.

sudo vim /etc/cloud/cloud.cfg

Update the serve_hostname line by setting it to Real Or add one if it doesn’t exist.

preserve_hostname: true

as follows

Restart the server to confirm that the host name is persistent.

sudo reboot

Recheck your server hostname.

$ uptime 
 06:57:02 up 0 min,  1 user,  load average: 0.13, 0.03, 0.01

$ hostname
fed31.computingforgeeks.com

You have it. In this article, you learned how to change / update the server host name in OpenStack, AWS, and DigitalOcean cloud platforms. The same process should work for other Cloud Platforms using Cloud-init.

Top rated AWS Cloud certification preparation

Build an AWS EC2 Machine Image (AMI) with Packer and Ansible

How to reset / change IAM user password on AWS

How to create a CentOS 8 KVM image template on OpenStack

How to assign a floating IP address to an instance in OpenStack

How to create an OpenStack instance with a fixed / static IP address

Sidebar