Unable to change the Linux hostname using custom extension

Somasundharam Arjunan 1 Reputation point
2020-06-01T08:58:49.713+00:00

I am trying to change the linux hostname using ARM Template , find my code below

{
"type": "Microsoft.Compute/virtualMachines/extensions",
"apiVersion": "2019-12-01",
"name": "[concat('VMName','/HostnameChange')]",
"location": "Central US",
"copy": {
"name": "HostnameCopy",
"count": 1
},
"properties": {
"publisher": "Microsoft.Azure.Extensions",
"type": "CustomScript",
"typeHandlerVersion": "2.1",
"autoUpgradeMinorVersion": true,
"settings": {
"skipDos2Unix": false
},
"protectedSettings": {
"commandToExecute": "hostnamectl set-hostname VMName"
}
}
}

Kindly help me to resolve

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
8,223 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. vipullag-MSFT 26,421 Reputation points
    2020-06-01T09:51:51.35+00:00

    @Somasundharam Arjunan

    What Linux OS you are seeing the issue?
    If its Suse, it could be due to the DHCLIENT, so in your custom script run this command try

    sed -i 's/DHCLIENT_SET_HOSTNAME="yes"/DHCLIENT_SET_HOSTNAME="no"/' /etc/sysconfig/network/dhcp and you may need to add reboot at the end of the script.

    Can you see what hostname is being displayed for these commands hostname cat /etc/hostname and cat /var/lib/waagent/published_hostname.
    From this log (waagent.log) you can see what operation is overriding the hostname change cat /var/log/waagent.log , to see if any issue with Azure Linux Agent.

    One more suggestion is to grep -r at /etc and see if there are any files with old hostname, try to change them and reboot the VM.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.