使用 Azure PowerShell 创建加密的虚拟网络

Azure 虚拟网络加密是 Azure 虚拟网络的一项功能。 虚拟网络加密使你能够在网络传输中无缝加密和解密内部网络流量,同时对性能和规模的影响保持在最小。 Azure 虚拟网络加密可保护从虚拟网络虚拟机流到虚拟机以及从虚拟机流到本地的数据。

先决条件

  • 具有活动订阅的 Azure 帐户。 创建帐户

  • 在本地安装了 Azure PowerShell。

  • 登录到 Azure PowerShell,并确保已选择要使用此功能的订阅。 有关详细信息,请参阅使用 Azure PowerShell 登录

  • 请确保 Az.Network 模块是 4.3.0 或更高版本。 要验证已安装的模块,请使用命令 Get-InstalledModule -Name Az.Network。 如果模块需要更新,请在必要时使用命令 Update-Module -Name Az.Network

如果选择在本地安装并使用 PowerShell,则本文需要 Azure PowerShell 模块 5.4.1 或更高版本。 运行 Get-Module -ListAvailable Az 查找已安装的版本。 如果需要进行升级,请参阅 Install Azure PowerShell module(安装 Azure PowerShell 模块)。 如果在本地运行 PowerShell,则还需运行 Connect-AzAccount -Environment AzureChinaCloud 以创建与 Azure 的连接。

创建资源组

Azure 资源组是在其中部署和管理 Azure 资源的逻辑容器。

使用 New-AzResourceGroup 在 chinanorth3 位置创建名为“test-rg”的资源组。

$rg =@{
    Name = 'test-rg'
    Location = 'chinanorth3'
}
New-AzResourceGroup @rg

创建虚拟网络

在本部分中,你要创建一个虚拟网络并启用虚拟网络加密。

使用 New-AzVirtualNetworkNew-AzVirtualNetworkSubnetConfig 创建虚拟网络。

## Create backend subnet config ##
$subnet = @{
    Name = 'subnet-1'
    AddressPrefix = '10.0.0.0/24'
}
$subnetConfig = New-AzVirtualNetworkSubnetConfig @subnet 

## Create the virtual network ##
$net = @{
    Name = 'vnet-1'
    ResourceGroupName = 'test-rg'
    Location = 'chinanorth3'
    AddressPrefix = '10.0.0.0/16'
    Subnet = $subnetConfig
    EnableEncryption = 'true'
    EncryptionEnforcementPolicy = 'AllowUnencrypted'
}
New-AzVirtualNetwork @net

在现有虚拟网络上启用

还可以使用 Set-AzVirtualNetwork 在现有虚拟网络上启用加密。

## Place the virtual network configuration into a variable. ##
$net = @{
    Name = 'vnet-1'
    ResourceGroupName = 'test-rg'
}
$vnet = Get-AzVirtualNetwork @net

## Enable encryption on the virtual network ##
$vnet.Encryption = @{
    Enabled = 'true'
    Enforcement = 'allowUnencrypted'
}
$vnet | Set-AzVirtualNetwork

重要

Azure 虚拟网络加密要求虚拟网络中有受支持的虚拟机 SKU 才能加密流量。

验证是否已启用加密

可以在虚拟网络中检查加密参数,以验证是否已在虚拟网络上启用加密。

使用 Get-AzVirtualNetwork 查看之前创建的虚拟网络的加密参数。

## Place the virtual network configuration into a variable. ##
$net = @{
    Name = 'vnet-1'
    ResourceGroupName = 'test-rg'
}
$vnet = Get-AzVirtualNetwork @net

要查看加密参数,请输入以下信息。

$vnet.Encryption
Enabled Enforcement
------- -----------
True   allowUnencrypted

清理资源

使用虚拟网络后,请使用 Remove-AzResourceGroup 删除资源组和组内所有资源。

Remove-AzResourceGroup -Name 'test-rg' -Force

后续步骤