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.
If you don't have an Azure subscription, create an Azure free account before you begin.
Sample 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 "1.2.3.4* with the values for your own.
az network dns record-set a add-record \
--g MyResourceGroup \
--z contoso.com \
--n www \
--a 1.2.3.4
# 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
Script explanation
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.
Command | Notes |
---|---|
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. |
Next steps
For more information on the Azure CLI, see Azure CLI documentation.
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for