Share via


Azure CLI 指令碼範例:建立 DNS 區域和記錄

此 Azure CLI 指令碼範例會建立 DNS 區域和網域名稱記錄。

若要執行此範例,請安裝最新版的 Azure CLI。 若要啟動,請執行 az login 來建立與 Azure 的連線。

Azure CLI 的範例專為 bash 殼層撰寫。 若要在 Windows PowerShell 或命令提示字元中執行此範例,您可能需要變更指令碼的元素。

如果您沒有 Azure 訂用帳戶,請在開始之前先建立 Azure 免費帳戶

範例指令碼

#!/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

清除部署

執行下列命令來移除資源群組、DNS 區域和所有相關資源。

az group delete -n myResourceGroup

指令碼說明

此指令碼使用下列命令來建立資源群組、虛擬機器、可用性設定組、負載平衡器和所有相關資源。 下表中的每個命令都會連結至命令特定的文件。

Command 注意
az group create 建立用來存放所有資源的資源群組。
az network dns zone create 建立 Azure DNS 區域。
az network dns record-set a add-record 將 A 記錄新增至 DNS 區域。
az network dns record-set list 列出 DNS 區域中的所有 A 記錄集。
az group delete 刪除資源群組,包括所有的巢狀資源。

下一步

如需 Azure CLI 的詳細資訊,請參閱 Azure CLI 文件