How can I change Linux Server hostname permanently in AWS EC2 / OpenStack / DigitalOcean / Azure Cloud platform?. When you create an instance in AWS or OpenStack cloud, the hostname is generated based on the name provided and virtualization environment it runs on. For AWS, the private IP address is usually used as part of assigned hostname.

In this guide, we will see how you can change an instance or VM hostname to persist reboots. Follow these few steps to change or set an instance / VM hostname in AWS, OpenStack & DigitalOcean cloud environments.

Change Linux Server hostname

I’m doing this in a system with Systemd, so hostnamectl command can be used for this purpose.

This is my current hostname:

$ hostnamectl 
   Static hostname: fed39.novalocal
         Icon name: computer-vm
           Chassis: vm
        Machine ID: d3ae97713a95466da1ef656ee2bb8456
           Boot ID: b8a8cfa70d78455b835269c88216c0a0
    Virtualization: kvm
....

I’ll change the hostname from fed39.novalocal to fed39.computingforgeeks.com

sudo hostnamectl set-hostname fed39.computingforgeeks.com

Let’s confirm a new hostname.

$ hostnamectl 
   Static hostname: fed39.computingforgeeks.com
         Icon name: computer-vm
           Chassis: vm
        Machine ID: d3ae97713a95466da1ef656ee2bb8456
           Boot ID: b8a8cfa70d78455b835269c88216c0a0
    Virtualization: kvm
...

$ cat /etc/hostname 
fed39.computingforgeeks.com

Modify Cloud-init configuration

If you reboot a server, the hostname will reset to auto generated name configured by Cloud-init. Cloud-init is the 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 preserve_hostname line by setting it to true or adding one if it doesn’t exist.

preserve_hostname: true

See below

change openstack aws server hostname

Reboot your server to confirm the hostname 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
fed39.computingforgeeks.com

There you have it. In this article, you learned how to change / update a server hostname in OpenStack, AWS & DigitalOcean cloud platform. The same procedure should apply to other Cloud Platforms using Cloud-init.

More guides:

LEAVE A REPLY

Please enter your comment!
Please enter your name here