Azure CLI script example: Create a DNS zone and record
This Azure CLI script example creates a DNS zone and record for a domain name.
To run this sample, install the latest version of the Azure CLI. To start, run
az login to create a connection with Azure.
Samples for the Azure CLI are written for the
bash shell. To run this sample in Windows PowerShell or Command Prompt, you may need to change
elements of the script.
#!/bin/bash # Create a resource group. az group create \ -n myResourceGroup \ -l eastus # Create a DNS zone. Substitute zone name "contoso.com" with the values for your own. az network dns zone create \ -g MyResourceGroup \ -n contoso.com # Create a DNS record. Substitute zone name "contoso.com" and IP address "184.108.40.206* with the values for your own. az network dns record-set a add-record \ --g MyResourceGroup \ --z contoso.com \ --n www \ --a 220.127.116.11 # Get a list the DNS records in your zone az network dns record-set list \ -g MyResourceGroup \ -z contoso.com
Clean up deployment
Run the following command to remove the resource group, DNS zone, and all related resources.
az group delete -n myResourceGroup
This script uses the following commands to create a resource group, virtual machine, availability set, load balancer, and all related resources. Each command in the table links to command specific documentation.
|az group create||Creates a resource group in which all resources are stored.|
|az network dns zone create||Creates an Azure DNS zone.|
|az network dns record-set a add-record||Adds an A record to a DNS zone.|
|az network dns record-set list||List all A record sets in a DNS zone.|
|az group delete||Deletes a resource group including all nested resources.|
For more information on the Azure CLI, see Azure CLI documentation.