Azure CLI 脚本示例:创建 DNS 区域和记录Azure CLI script example: Create a DNS zone and record

此 Azure CLI 脚本示例为域名创建 DNS 区域和记录。This Azure CLI script example creates a DNS zone and record for a domain name.

若要运行此示例,请安装最新版本的 Azure CLITo run this sample, install the latest version of the Azure CLI. 若要开始,请运行 az login 以创建与 Azure 的连接。To start, run az login to create a connection with Azure.

适用于 Azure CLI 的示例是针对 bash shell 编写的。Samples for the Azure CLI are written for the bash shell. 若要在 Windows PowerShell 或命令提示符中运行此示例,可能需要更改脚本的元素。To run this sample in Windows PowerShell or Command Prompt, you may need to change elements of the script.

如果没有 Azure 订阅,可在开始前创建一个试用帐户If you don't have an Azure subscription, create a trial account before you begin.

示例脚本Sample script


# Create a resource group.
az group create \
  -n myResourceGroup \
  -l chinaeast

# Create a DNS zone. Substitute zone name "" with the values for your own.

az network dns zone create \
  -g MyResourceGroup \

# Create a DNS record. Substitute zone name "" and IP address "* with the values for your own.

az network dns record-set a add-record \
  --g MyResourceGroup \
  --z \
  --n www \

# Get a list the DNS records in your zone
az network dns record-set list \
  -g MyResourceGroup \ 

清理部署Clean up deployment

运行以下命令以删除资源组、DNS 区域和所有相关资源。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.

CommandCommand 说明Notes
az group createaz group create 创建用于存储所有资源的资源组。Creates a resource group in which all resources are stored.
az network dns zone createaz network dns zone create 创建 Azure DNS 区域。Creates an Azure DNS zone.
az network dns record-set a add-recordaz network dns record-set a add-record A 记录添加到 DNS 区域。Adds an A record to a DNS zone.
az network dns record-set listaz network dns record-set list 列出 DNS 区域中的所有 A 记录集。List all A record sets in a DNS zone.
az group deleteaz group delete 删除资源组,包括所有嵌套的资源。Deletes a resource group including all nested resources.

后续步骤Next steps

有关 Azure CLI 的详细信息,请参阅 Azure CLI 文档For more information on the Azure CLI, see Azure CLI documentation.