快速入门:使用 Azure PowerShell 创建和配置 Azure DDoS 网络保护

开始使用 Azure PowerShell 实现 Azure DDoS 网络保护。

DDoS 防护计划跨订阅定义了一组已启用 DDoS 网络防护标准的虚拟网络。 可以为组织配置一个 DDoS 防护计划,然后从多个订阅将虚拟网络链接到相同计划。

在本快速入门中,你将创建一个 DDoS 防护计划,并将其链接到虚拟网络。

DDoS 网络保护的示意图。

先决条件

  • 具有活动订阅的 Azure 帐户。 创建试用版订阅
  • 本地安装的 Azure PowerShell 或 Azure 本地 Shell

注意

建议使用 Azure Az PowerShell 模块与 Azure 交互。 若要开始,请参阅安装 Azure PowerShell。 若要了解如何迁移到 Az PowerShell 模块,请参阅 将 Azure PowerShell 从 AzureRM 迁移到 Az

创建 DDoS 防护计划

在 Azure 中,可将相关的资源分配到资源组。 可以使用现有资源组,也可以创建新组。

若要创建资源组,请使用 New-AzResourceGroup。 在此示例中,我们将资源组命名为“MyResourceGroup”,并使用“中国东部”位置:

New-AzResourceGroup -Name MyResourceGroup -Location "China East"

现在,创建名为 MyDdosProtectionPlan 的 DDoS 防护计划:

New-AzDdosProtectionPlan -ResourceGroupName MyResourceGroup -Name MyDdosProtectionPlan -Location "China East"

为虚拟网络启用 DDoS

为新的虚拟网络启用 DDoS

创建虚拟网络时,可以启用 DDoS 防护。 在此示例中,我们将为虚拟网络命名为 MyVnet

#Gets the DDoS protection plan ID
$ddosProtectionPlanID = Get-AzDdosProtectionPlan -ResourceGroupName MyResourceGroup -Name MyDdosProtectionPlan

#Creates the virtual network
New-AzVirtualNetwork -Name MyVnet -ResourceGroupName MyResourceGroup -Location "China East" -AddressPrefix 10.0.0.0/16 -DdosProtectionPlan $ddosProtectionPlanID.Id -EnableDdosProtection  

为现有虚拟网络启用 DDoS

创建 DDoS 防护计划时,可以关联现有虚拟网络:

#Gets the DDoS protection plan ID
$ddosProtectionPlanID = Get-AzDdosProtectionPlan -ResourceGroupName MyResourceGroup -Name MyDdosProtectionPlan

# Gets the most updated version of the virtual network
$vnet = Get-AzVirtualNetwork -Name MyVnet -ResourceGroupName MyResourceGroup
$vnet.DdosProtectionPlan = New-Object Microsoft.Azure.Commands.Network.Models.PSResourceId

# Update the properties and enable DDoS protection
$vnet.DdosProtectionPlan.Id = $ddosProtectionPlanID.Id
$vnet.EnableDdosProtection = $true
$vnet | Set-AzVirtualNetwork

为虚拟网络禁用 DDoS

若要为虚拟网络禁用 DDoS 防护,请执行以下操作:

# Gets the most updated version of the virtual network
$vnet = Get-AzVirtualNetwork -Name MyVnet -ResourceGroupName MyResourceGroup
$vnet.DdosProtectionPlan = $null
$vnet.EnableDdosProtection = $false
$vnet | Set-AzVirtualNetwork

验证并测试

检查 DDoS 防护计划的详细信息,并验证命令是否返回正确的 DDoS 防护计划详细信息。

Get-AzDdosProtectionPlan -ResourceGroupName MyResourceGroup -Name MyDdosProtectionPlan

检查虚拟网络的详细信息,并验证是否已启用 DDoS 保护计划。

Get-AzVirtualNetwork -Name MyVnet -ResourceGroupName MyResourceGroup

清理资源

可保留资源以供下一教程使用。 如果不再需要,请删除“MyResourceGroup”资源组。 删除资源组时,DDoS 防护计划及其所有相关资源也会一起删除。

Remove-AzResourceGroup -Name MyResourceGroup

注意

若要删除 DDoS 保护计划,请先取消关联所有虚拟网络。

后续步骤

要了解如何查看和配置 DDoS 防护计划的遥测,请继续阅读教程。