将 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.

先决条件Prerequisites

  • 如果需要,请安装 Azure CLI 来运行 CLI 参考命令。If you prefer, install the Azure CLI to run CLI reference commands.
    • 如果使用的是本地安装,请使用 az login 命令登录到 Azure CLI。If you're using a local installation, sign in to the Azure CLI by using the az login command. 若要完成身份验证过程,请遵循终端中显示的步骤。To finish the authentication process, follow the steps displayed in your terminal. 有关其他登录选项,请参阅登录 Azure CLIFor additional sign-in options, see Sign in with the Azure CLI.
    • 出现提示时,请在首次使用时安装 Azure CLI 扩展。When you're prompted, install Azure CLI extensions on first use. 有关扩展详细信息,请参阅使用 Azure CLI 的扩展For more information about extensions, see Use extensions with the Azure CLI.
    • 运行 az version 以查找安装的版本和依赖库。Run az version to find the version and dependent libraries that are installed. 若要升级到最新版本,请运行 az upgradeTo upgrade to the latest version, run az upgrade.
  • 本文需要 Azure CLI 2.0.28 或更高版本。This article requires version 2.0.28 or later of the Azure CLI.

备注

请先运行 az cloud set -n AzureChinaCloud 更改云环境,然后才能在 Azure 中国中使用 Azure CLI。Before you can use Azure CLI 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 Azure Public Cloud, run az cloud set -n AzureCloud again.

创建 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"  "fd00:db8:deca::/48"

az network vnet subnet update \
--vnet-name myVnet \
--name mySubnet \
--resource-group MyResourceGroupSLB \
--address-prefixes  "10.0.0.0/24"  "fd00:db8: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?