Persist Azure Linux VM’s hostname

Persist Azure Linux virtual machine’s hostname

To persist Azure Linux virtual machine’s hostname permanently for an Azure Linux Virtual Machine, you need to ensure that, you have an Azure Linux agent installed in this machine. To install WA Linux Agent in your virtual machine, please refer the link http://admindiary.com/install-microsoft-azure-linux-agent-waagent/

Once the WA Linux Agent or WAAGENT is installed in your machine, you may need to modify the WAAGENT configuration to monitor hostname changes and update the network. To save or persist your hostname permanently, edit the file /etc/waagent.conf and modify the below line,

Provisioning.MonitorHostName=y

vi /etc/waagent.conf
Provisioning.MonitorHostName=y

Once done, please proceed to restart the WAAGENT service.

For Ubuntu,please execute the below command,

sudo service walinuxagent restart

For CoreOS, please execute the command,

sudo systemctl restart waagent

If the above steps does not work, you may need to try to install the service by executing the below command,

sudo waagent -install

Now you can change the hostname and it will be updated, both locally and and also at the Azure Portal.

You can execute the below command to change your machine’s hostname.

sudo hostname

The command to change the hostname is mentioned in the doc – https://docs.microsoft.com/en-us/azure/virtual-machines/virtual-machines-linux-intro-on-azure?toc=%2fazure%2fvirtual-machines%2flinux%2ftoc.json#hostnamechanges

Even after executing the above steps, if the hostname change is not persisting, you may need to edit the file /var/lib/waagent/ovf-env.xml and update the hostname.

viĀ /var/lib/waagent/ovf-env.xml

Then look for the below line and change your hostname.

<HostName>YourHostname</HostName>

Sample File is pasted below ,


1.0
LinuxProvisioningConfiguration
testvm
testuser
true



3543..
/home/testuser/.ssh/authorized_keys



XrVtUmeIc.....



1.0

kms.core.windows.net
true
VMAgentPackage.zip



Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.