Share via


快速入門:使用 Azure CLI 建立及設定 Azure DDoS 網路保護

使用 Azure CLI 開始使用 Azure DDoS 網路保護。

DDoS 保護方案會定義一組跨訂用帳戶啟用 DDoS 網路保護的虛擬網路。 您可以為您的組織設定一個 DDoS 保護方案,並將多個訂用帳戶的虛擬網路連結至相同的方案。

在本快速入門中,您將建立 DDoS 保護計劃,並將其連結至虛擬網路。

Diagram of DDoS Network Protection.

必要條件

  • 具有有效訂用帳戶的 Azure 帳戶。 免費建立帳戶
  • 在本機安裝 Azure CLI 或 Azure Cloud Shell

Azure Cloud Shell

Azure Cloud Shell 是裝載於 Azure 中的互動式殼層環境,可在瀏覽器中使用。 您可以使用 Bash 或 PowerShell 搭配 Cloud Shell,與 Azure 服務共同使用。 您可以使用 Cloud Shell 預先安裝的命令,執行本文提到的程式碼,而不必在本機環境上安裝任何工具。

要啟動 Azure Cloud Shell:

選項 範例/連結
選取程式碼或命令區塊右上角的 [試試看]。 選取 [試試看] 並不會自動將程式碼或命令複製到 Cloud Shell 中。 Screenshot that shows an example of Try It for Azure Cloud Shell.
請前往 https://shell.azure.com,或選取 [啟動 Cloud Shell] 按鈕,在瀏覽器中開啟 Cloud Shell。 Button to launch Azure Cloud Shell.
選取 Azure 入口網站右上方功能表列上的 [Cloud Shell] 按鈕。 Screenshot that shows the Cloud Shell button in the Azure portal

若要使用 Azure Cloud Shell:

  1. 啟動 Cloud Shell。

  2. 選取程式碼區塊 (或命令區塊) 上的 [複製] 按鈕以複製程式碼或命令。

  3. 透過在 Windows 和 Linux 上選取 Ctrl+Shift+V;或在 macOS 上選取 Cmd+Shift+V,將程式碼或命令貼到 Cloud Shell 工作階段中。

  4. 選取 Enter 鍵執行程式碼或命令。

如果您選擇在本機安裝和使用 CLI,本快速入門需要 Azure CLI 2.0.56 版或更新版本。 若要尋找版本,請執行 az --version。 如果您需要安裝或升級,請參閱安裝 Azure CLI 模組

建立 DDoS 保護方案

在 Azure 中,您會將相關的資源配置給資源群組。 您可以使用現有的資源群組或建立新的資源群組。

若要建立資源群組,請使用 az group create。 在此範例中,我們會將資源組 名命名為 MyResourceGroup ,並使用 美國 東部位置:

az group create \
    --name MyResourceGroup \
    --location eastus

現在建立名為 MyDdosProtectionPlanDDoS 保護計劃:

az network ddos-protection create \
    --resource-group MyResourceGroup \
    --name MyDdosProtectionPlan

啟用虛擬網路的 DDoS 保護

為新的虛擬網路啟用 DDoS 保護

您可以在建立虛擬網路時啟用 DDoS 保護。 在此範例中,我們會將虛擬網路 命名為 MyVnet

az network vnet create \
    --resource-group MyResourceGroup \
    --name MyVnet \
    --location eastus \
    --ddos-protection-plan MyDdosProtectionPlan \
    --ddos-protection true

注意

當虛擬網路啟用 DDoS 保護時,您無法將虛擬網路移至另一個資源群組或訂用帳戶。 如果您需要移動已啟用 DDoS 保護的虛擬網路,請先停用 DDoS 保護、移動虛擬網路,然後啟用 DDoS 保護。 移動之後,虛擬網路中所有受保護公用IP位址的自動調整原則閾值會重設。

為現有的虛擬網路啟用 DDoS 保護

建立 DDoS 保護方案,您可以將一或多個虛擬網路與方案產生關聯。 若要新增多個虛擬網路,只需列出名稱或標識符,以空格分隔。 在此範例中,我們將新增 MyVnet

az group create \
    --name MyResourceGroup \
    --location eastus

az network ddos-protection create \
    --resource-group MyResourceGroup \
    --name MyDdosProtectionPlan 
    --vnets MyVnet

或者,您可以為指定的虛擬網路啟用 DDoS 保護:

az network vnet update \
    --resource-group MyResourceGroup \
    --name MyVnet \
    --ddos-protection-plan MyDdosProtectionPlan \
    --ddos-protection true

停用虛擬網路的 DDoS 保護

更新指定的虛擬網路以停用 DDoS 保護:

az network vnet update \
    --resource-group MyResourceGroup \
    --name MyVnet \
    --ddos-protection-plan MyDdosProtectionPlan \
    --ddos-protection false
    

驗證和測試

首先,檢查 DDoS 保護計劃的詳細數據:

az network ddos-protection show \
    --resource-group MyResourceGroup \
    --name MyDdosProtectionPlan

確認命令會傳回 DDoS 保護計畫的正確詳細數據。

清除資源

您可以保留下一個教學課程的資源。 如果不再需要,請刪除 MyResourceGroup 資源群組。 當您刪除資源群組時,也會刪除 DDoS 保護計劃及其所有相關資源。

若要刪除資源群組,請使用 az group delete

az group delete \
--name MyResourceGroup 

注意

如果您想要刪除 DDoS 保護計畫,您必須先將所有虛擬網路與它解除關聯。

下一步

若要瞭解如何檢視及設定 DDoS 保護計劃的遙測,請繼續進行教學課程。