在本文中,你将向现有虚拟网络添加 IPv6 支持。 你将使用 IPv4 和 IPv6 地址配置现有虚拟机。 完成后,现有虚拟网络将支持专用 IPv6 地址。 现有的虚拟机网络配置包含公共和专用 IPv4 和 IPv6 地址。 从 Azure 门户、Azure CLI 或 Azure PowerShell 中进行选择,以完成本文中的步骤。
先决条件
具有活动订阅的 Azure 帐户。 创建帐户。
在本地安装了 Azure PowerShell
如果选择在本地安装并使用 PowerShell,则本文需要 Azure PowerShell 模块 5.4.1 或更高版本。 运行 Get-Module -ListAvailable Az
查找已安装的版本。 如果需要进行升级,请参阅 Install Azure PowerShell module(安装 Azure PowerShell 模块)。 如果在本地运行 PowerShell,则还需运行 Connect-AzAccount
以创建与 Azure 的连接。
将 IPv6 添加到虚拟网络
在本部分中,你将向现有虚拟网络添加 IPv6 地址空间和子网。
登录到 Azure 门户。
在门户顶部的搜索框中,输入“虚拟网络”。 在搜索结果中,选择“虚拟网络”。
在“虚拟网络”中,选择“myVNet”。
在“设置”中选择“地址空间”。
选中“添加其他地址范围”框。 输入“2404:f800:8000:122::/63”。
选择“保存”。
在“设置”中选择“子网”。
在“子网”中,从列表中选择子网名称。 在此示例中,子网名称为 default。
在子网配置中,选择“添加 IPv6 地址空间”框。
在“IPv6 地址空间”中,输入“2404:f800:8000:122::/64”。
选择“保存”。
在本部分中,你将向现有虚拟网络添加 IPv6 地址空间和子网。
使用 az network vnet update 更新虚拟网络。
az network vnet update \
--address-prefixes 10.0.0.0/16 2404:f800:8000:122::/63 \
--resource-group myResourceGroup \
--name myVNet
使用 az network vnet subnet update 创建子网。
az network vnet subnet update \
--address-prefixes 10.0.0.0/24 2404:f800:8000:122::/64 \
--name myBackendSubnet \
--resource-group myResourceGroup \
--vnet-name myVNet
在本部分中,你将向现有虚拟网络添加 IPv6 地址空间和子网。
使用 Set-AzVirtualNetwork 更新虚拟网络。
## Place your virtual network into a variable. ##
$net = @{
Name = 'myVNet'
ResourceGroupName = 'myResourceGroup'
}
$vnet = Get-AzVirtualNetwork @net
## Place address space into a variable. ##
$IPAddressRange = '2404:f800:8000:122::/63'
## Add the address space to the virtual network configuration. ##
$vnet.AddressSpace.AddressPrefixes.Add($IPAddressRange)
## Save the configuration to the virtual network. ##
Set-AzVirtualNetwork -VirtualNetwork $vnet
使用 Set-AzVirtualNetworkSubnetConfig 将新的 IPv6 子网添加到虚拟网络。
## Place your virtual network into a variable. ##
$net = @{
Name = 'myVNet'
ResourceGroupName = 'myResourceGroup'
}
$vnet = Get-AzVirtualNetwork @net
## Create the subnet configuration. ##
$sub = @{
Name = 'myBackendSubnet'
AddressPrefix = '10.0.0.0/24','2404:f800:8000:122::/64'
VirtualNetwork = $vnet
}
Set-AzVirtualNetworkSubnetConfig @sub
## Save the configuration to the virtual network. ##
Set-AzVirtualNetwork -VirtualNetwork $vnet
创建 IPv6 公共 IP 地址
在本部分中,你将为虚拟机创建一个 IPv6 公共 IP 地址。
在门户顶部的搜索框中,输入“公共 IP 地址”。 在搜索结果中,选择“公共 IP 地址”。
选择“+ 新建”。
在“创建公共 IP 地址”中,输入或选择以下信息。
设置 |
值 |
IP 版本 |
选择“IPv6”。 |
SKU |
选择“标准”。 |
IPv6 IP 地址配置 |
|
名称 |
输入“myPublicIP-IPv6”。 |
空闲超时(分钟) |
保留默认值“4”。 |
订阅 |
选择订阅。 |
资源组 |
选择你的资源组。 在本示例中,资源组的名称为 myResourceGroup。 |
位置 |
选择你的位置。 在此示例中,位置为“中国北部 3”。 |
可用性区域 |
选择“区域冗余”。 |
选择创建。
在本部分中,你将为虚拟机创建一个 IPv6 公共 IP 地址。
使用 az network public-ip create 创建公共 IP 地址。
az network public-ip create \
--resource-group myResourceGroup \
--name myPublicIP-Ipv6 \
--sku Standard \
--version IPv6 \
--zone 1 2 3
在本部分中,你将为虚拟机创建一个 IPv6 公共 IP 地址。
使用 New-AzPublicIpAddress 创建该公共 IP 地址。
$ip6 = @{
Name = 'myPublicIP-IPv6'
ResourceGroupName = 'myResourceGroup'
Location = 'eastus2'
Sku = 'Standard'
AllocationMethod = 'Static'
IpAddressVersion = 'IPv6'
Zone = 1,2,3
}
New-AzPublicIpAddress @ip6
将 IPv6 配置添加到虚拟机
在本部分中,你将配置虚拟机的网络接口,以包含专用和公用 IPv6 地址。
在门户顶部的搜索框中,输入“虚拟机”。 在搜索结果中,选择“虚拟机”。
选择“myVM”或现有虚拟机名称。
在“设置”中选择“网络” 。
在“网络接口:”旁边选择你的网络接口名称。 在此示例中,网络接口名为 myvm404。
在网络接口的“设置”中选择“IP 配置”。
在“IP 配置”中,选择“+ 添加” 。
在“添加 IP 配置”中,输入或选择以下信息。
设置 |
值 |
名称 |
输入“Ipv6config”。 |
IP 版本 |
选择“IPv6”。 |
专用 IP 地址设置 |
|
分配 |
保留默认值“动态”。 |
公共 IP 地址 |
选择“关联”。 |
公共 IP 地址 |
选择“myPublic-IPv6”。 |
选择“确定”。
使用 az network nic ip-config create 创建网络接口的 IPv6 配置。 此示例中使用的 --nic-name
是 myvm569。 将此值替换为虚拟机中网络接口的名称。
az network nic ip-config create \
--resource-group myResourceGroup \
--name Ipv6config \
--nic-name myvm569 \
--private-ip-address-version IPv6 \
--vnet-name myVNet \
--subnet myBackendSubnet \
--public-ip-address myPublicIP-IPv6
使用 New-AzNetworkInterfaceIpConfig 为网络接口创建 IPv6 配置。 此示例中使用的 -Name
是 myvm569。 将此值替换为虚拟机中网络接口的名称。
## Place your virtual network into a variable. ##
$net = @{
Name = 'myVNet'
ResourceGroupName = 'myResourceGroup'
}
$vnet = Get-AzVirtualNetwork @net
## Place your virtual network subnet into a variable. ##
$sub = @{
Name = 'myBackendSubnet'
VirtualNetwork = $vnet
}
$subnet = Get-AzVirtualNetworkSubnetConfig @sub
## Place the IPv6 public IP address you created previously into a variable. ##
$pip = @{
Name = 'myPublicIP-IPv6'
ResourceGroupName = 'myResourceGroup'
}
$publicIP = Get-AzPublicIPAddress @pip
## Place the network interface into a variable. ##
$net = @{
Name = 'myvm569'
ResourceGroupName = 'myResourceGroup'
}
$nic = Get-AzNetworkInterface @net
## Create the configuration for the network interface. ##
$ipc = @{
Name = 'Ipv6config'
Subnet = $subnet
PublicIpAddress = $publicIP
PrivateIpAddressVersion = 'IPv6'
}
$ipconfig = New-AzNetworkInterfaceIpConfig @ipc
## Add the IP configuration to the network interface. ##
$nic.IpConfigurations.Add($ipconfig)
## Save the configuration to the network interface. ##
$nic | Set-AzNetworkInterface
后续步骤
本文介绍了如何将双堆栈 IP 配置添加到现有虚拟网络和虚拟机。
有关 Azure 中 IPv6 和 IP 地址的详细信息,请参阅: