将 IPv6 添加到 Azure 虚拟网络中的 IPv4 应用程序 - Azure CLIAdd IPv6 to an IPv4 application in Azure virtual network - Azure CLI

本文介绍如何通过 Azure CLI,将 IPv6 地址添加到对标准负载均衡器使用 Azure 虚拟网络中 IPv4 公共 IP 地址的应用程序。This article shows you how to add IPv6 addresses to an application that is using IPv4 public IP address in an Azure virtual network for a Standard Load Balancer using Azure CLI. 就地升级涉及到虚拟网络和子网、采用 IPv4 + IPV6 前端配置的标准负载均衡器、包含采用 IPv4 + IPv6 配置的 NIC 的 VM、网络安全组和公共 IP。The in-place upgrade includes a virtual network and subnet, a Standard Load Balancer with IPv4 + IPV6 frontend configurations, VMs with NICs that have a IPv4 + IPv6 configurations, network security group, and public IPs.

备注

在 Azure China 中使用 Azure CLI 2.0 之前,请首先运行 az cloud set -n AzureChinaCloud 更改云环境。Before you can use Azure CLI 2.0 in Azure China, please run az cloud set -n AzureChinaCloud first to change the cloud environment. 如果要切换回全局 Azure,请再次运行 az cloud set -n AzureCloudIf you want to switch back to Global Azure, run az cloud set -n AzureCloud again.

本快速入门需要使用 Azure CLI 版本 2.0.28 或更高版本。This quickstart requires you to use Azure CLI version 2.0.28 or later. 若要查找已安装的版本,请运行 az --versionTo find your installed version, run az --version. 有关安装或升级信息,请参阅安装 Azure CLISee Install Azure CLI for install or upgrade info.

先决条件Prerequisites

本文假设已根据以下文章所述部署了一个标准负载均衡器:快速入门:创建标准负载均衡器 - Azure CLIThis article assumes that you deployed a Standard Load Balancer as described in Quickstart: Create a Standard Load Balancer - Azure CLI.

创建 IPv6 地址Create IPv6 addresses

使用 az network public-ip create 为标准负载均衡器创建公共 IPv6 地址。Create public IPv6 address with with az network public-ip create for your Standard Load Balancer. 以下示例在 myResourceGroupSLB 资源组中创建名为 PublicIP_v6 的 IPv6 公共 IP 地址:The following example creates an IPv6 public IP address named PublicIP_v6 in the myResourceGroupSLB resource group:

az network public-ip create \
--name PublicIP_v6 \
--resource-group MyResourceGroupSLB \
--location ChinaEast \
--sku Standard \
--allocation-method static \
--version IPv6

配置 IPv6 负载均衡器前端Configure IPv6 load balancer frontend

运行 az network lb frontend-ip create 配置使用新 IPv6 IP 地址的负载均衡器,如下所示:Configure the load balancer with the new IPv6 IP address using az network lb frontend-ip create as follows:

az network lb frontend-ip create \
--lb-name myLoadBalancer \
--name dsLbFrontEnd_v6 \
--resource-group MyResourceGroupSLB \
--public-ip-address PublicIP_v6

配置 IPv6 负载均衡器后端池Configure IPv6 load balancer backend pool

运行 az network lb address-pool create 为使用 IPv6 地址的 NIC 创建后端池,如下所示:Create the backend pool for NICs with IPv6 addresses using az network lb address-pool create as follows:

az network lb address-pool create \
--lb-name myLoadBalancer \
--name dsLbBackEndPool_v6 \
--resource-group MyResourceGroupSLB

配置 IPv6 负载均衡器规则Configure IPv6 load balancer rules

使用 az network lb rule create 创建 IPv6 负载均衡器规则。Create IPv6 load balancer rules with az network lb rule create.

az network lb rule create \
--lb-name myLoadBalancer \
--name dsLBrule_v6 \
--resource-group MyResourceGroupSLB \
--frontend-ip-name dsLbFrontEnd_v6 \
--protocol Tcp \
--frontend-port 80 \
--backend-port 80 \
--backend-pool-name dsLbBackEndPool_v6

添加 IPv6 地址范围Add IPv6 address ranges

将 IPv6 地址范围添加到托管负载均衡器的虚拟网络和子网,如下所示:Add IPv6 address ranges to the virtual network and subnet hosting the load balancer as follows:

az network vnet update \
--name myVnet  \
--resource-group MyResourceGroupSLB \
--address-prefixes  "10.0.0.0/16"  "ace:cab:deca::/48"

az network vnet subnet update \
--vnet-name myVnet \
--name mySubnet \
--resource-group MyResourceGroupSLB \
--address-prefixes  "10.0.0.0/24"  "ace:cab:deca:deed::/64"  

将 IPv6 配置添加到 NICAdd IPv6 configuration to NICs

运行 az network nic ip-config create 配置使用 IPv6 地址的 VM NIC,如下所示:Configure the VM NICs with an IPv6 address using az network nic ip-config create as follows:

az network nic ip-config create \
--name dsIp6Config_NIC1 \
--nic-name myNicVM1 \
--resource-group MyResourceGroupSLB \
--vnet-name myVnet \
--subnet mySubnet \
--private-ip-address-version IPv6 \
--lb-address-pools dsLbBackEndPool_v6 \
--lb-name dsLB

az network nic ip-config create \
--name dsIp6Config_NIC2 \
--nic-name myNicVM2 \
--resource-group MyResourceGroupSLB \
--vnet-name myVnet \
--subnet mySubnet \
--private-ip-address-version IPv6 \
--lb-address-pools dsLbBackEndPool_v6 \
--lb-name myLoadBalancer

az network nic ip-config create \
--name dsIp6Config_NIC3 \
--nic-name myNicVM3 \
--resource-group MyResourceGroupSLB \
--vnet-name myVnet \
--subnet mySubnet \
--private-ip-address-version IPv6 \
--lb-address-pools dsLbBackEndPool_v6 \
--lb-name myLoadBalancer

在 Azure 门户中查看 IPv6 双堆栈虚拟网络View IPv6 dual stack virtual network in Azure portal

可以在 Azure 门户中查看 IPv6 双堆栈虚拟网络,如下所示:You can view the IPv6 dual stack virtual network in Azure portal as follows:

  1. 在门户的搜索栏中输入 myVnetIn the portal's search bar, enter myVnet.

  2. 当“myVnet”出现在搜索结果中时,将其选中。****When myVnet appears in the search results, select it. 此时会启动名为 myVNet 的双堆栈虚拟网络的“概述”页。****This launches the Overview page of the dual stack virtual network named myVNet. 该双堆栈虚拟网络显示了位于 mySubnet 双堆栈子网中的三个 NIC,这些 NIC 采用 IPv4 和 IPv6 配置。The dual stack virtual network shows the three NICs with both IPv4 and IPv6 configurations located in the dual stack subnet named mySubnet.

    Azure 中的 IPv6 双堆栈虚拟网络

清理资源Clean up resources

如果不再需要资源组、VM 和所有相关的资源,可以使用 Remove-AzResourceGroup 命令将其删除。When no longer needed, you can use the Remove-AzResourceGroup command to remove the resource group, VM, and all related resources.

az group delete --name MyAzureResourceGroupSLB

后续步骤Next steps

在本文中,你已将采用 IPv4 前端 IP 配置的现有标准负载均衡器更新为双堆栈(IPv4 和 IPv6)配置。In this article, you updated an existing Standard Load Balancer with a IPv4 frontend IP configuration to a dual stack (IPv4 and IPv6) configuration. 你还将 IPv6 配置添加到了后端池中 VM 的 NIC。You also added IPv6 configurations to the NICs of the VMs in the backend pool. 若要详细了解 Azure 虚拟网络中的 IPv6 支持,请参阅 Azure 虚拟网络 IPv6 是什么?To learn more about IPv6 support in Azure virtual networks, see What is IPv6 for Azure Virtual Network?