1 min read

How to get public DNS name of a virtual machine using the Azure CLI

With the Azure CLI, use the command az vm list-ip-addresses to get the public IP address name of a virtual machine. The result will be stored in a variable.

PUBLIC_IP_NAME=$(az vm list-ip-addresses \
  --resource-group $RESOURCE_GROUP \
  --query "[].virtualMachine.network.publicIpAddresses[0].name" \
  --output tsv)

Now, use the command az network public-ip show with the public IP address name from the previous step to get then public DNS name.

az network public-ip show \
  --resource-group $RESOURCE_GROUP \
  --name $PUBLIC_IP_NAME \
  --query "dnsSettings.fqdn"

And the command output will be something like this:


For more details, click on the link below to access the official documentation

az vm