Search code examples
azureazure-virtual-machineazure-resource-managerazure-resource-group

Azure VM InternalDnsSuffix


When you create a VM in Azure and ssh to it and run 'hostname -f' you get a hostname in the format of "vmname.InternalDnsSuffix". Is there a programatic/scriptable way to get InternalDnsSuffix for a ResourceGroup/Subscription/Subnet? I know I can get it for a running VM, but where do I get it for a stopped VM? Is there some way that I can just get it once for a set of VMs instead of querying each VM independently?


Solution

  • Is there a programatic/scriptable way to get InternalDnsSuffix for a ResourceGroup/Subscription/Subnet?

    That attribute only associate to Azure VM, so you should get this information from that VM.

    You can use Azure REST API to run hostname -f command to get internal DNS suffix from a running VM:

    POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/runCommand?api-version=2017-03-30
    

    More information about run command via REST API, please refer to this article.

    Based on my knowledge, we can't get the dns suffix from a stopped VM or get internal dns suffix once for a set.