此 Azure CLI 指令碼範例會建立 DNS 區域和網域名稱記錄。
若要執行此範例,請安裝最新版的 Azure CLI。 若要啟動,請執行 az login 來建立與 Azure 的連線。
Azure CLI 的範例是針對 bash 命令列介面撰寫的。 若要在 Windows PowerShell 或命令提示字元中執行此範例,您可能需要變更指令碼的元素。
如果您沒有 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
腳本說明
此指令碼使用下列命令來建立資源群組、虛擬機器、可用性設定組、負載平衡器和所有相關資源。 下表中的每個命令都會連結至命令特定的文件。
| 指令 | 備註 |
|---|---|
| az group create (建立群組) | 建立用來存放所有資源的資源群組。 |
| az network dns zone create 建立 DNS 區域 | 建立 Azure DNS 區域。 |
| az network dns record-set a add-record(用於添加 DNS 記錄的命令) | 將 A 記錄新增至 DNS 區域。 |
| az network dns record-set list | 列出 DNS 區域中的所有 A 記錄集。 |
| az group delete(刪除群組) | 刪除資源組,及其下的所有資源。 |
後續步驟
如需 Azure CLI 的詳細資訊,請參閱 Azure CLI 文件。