|
| 1 | +--- |
| 2 | +title: Add a dual-stack network to an existing virtual machine - Azure PowerShell |
| 3 | +titleSuffix: Azure Virtual Network |
| 4 | +description: Learn how to add a dual-stack network to an existing virtual machine using Azure PowerShell. |
| 5 | +author: asudbring |
| 6 | +ms.author: allensu |
| 7 | +ms.service: virtual-network |
| 8 | +ms.subservice: ip-services |
| 9 | +ms.topic: how-to |
| 10 | +ms.date: 08/24/2022 |
| 11 | +ms.custom: template-how-to |
| 12 | +ms.devlang: |
| 13 | +--- |
| 14 | + |
| 15 | +# Add a dual-stack network to an existing virtual machine using Azure PowerShell |
| 16 | + |
| 17 | +In this article, you'll add IPv6 support to an existing virtual network. You'll configure an existing virtual machine with both IPv4 and IPv6 addresses. When completed, the existing virtual network will support private IPv6 addresses. The existing virtual machine network configuration will contain a public and private IPv4 and IPv6 address. |
| 18 | + |
| 19 | +## Prerequisites |
| 20 | + |
| 21 | +- An Azure account with an active subscription. [Create one for free](https://azure.microsoft.com/free/?ref=microsoft.com&utm_source=microsoft.com&utm_medium=docs&utm_campaign=visualstudio). |
| 22 | + |
| 23 | +- Azure PowerShell installed locally or Azure Cloud Shell |
| 24 | + |
| 25 | +If you choose to install and use PowerShell locally, this article requires the Azure PowerShell module version 5.4.1 or later. Run `Get-Module -ListAvailable Az` to find the installed version. If you need to upgrade, see [Install Azure PowerShell module](/powershell/azure/install-Az-ps). If you're running PowerShell locally, you also need to run `Connect-AzAccount` to create a connection with Azure. |
| 26 | + |
| 27 | +- An existing virtual network, public IP address and virtual machine in your subscription that is configured for IPv4 support only. For more information about creating a virtual network, public IP address and a virtual machine, see [Quickstart: Create a Linux virtual machine in Azure with PowerShell](/azure/virtual-machines/linux/quick-create-powershell). |
| 28 | + |
| 29 | + - The example virtual network used in this article is named **myVNet**. Replace this value with the name of your virtual network. |
| 30 | + |
| 31 | + - The example virtual machine used in this article is named **myVM**. Replace this value with the name of your virtual machine. |
| 32 | + |
| 33 | + - The example public IP address used in this article is named **myPublicIP**. Replace this value with the name of your public IP address. |
| 34 | + |
| 35 | +## Add IPv6 to virtual network |
| 36 | + |
| 37 | +In this section, you'll add an IPv6 address space and subnet to your existing virtual network. |
| 38 | + |
| 39 | +Use [Set-AzVirtualNetwork](/powershell/module/az.network/set-azvirtualnetwork) to update the virtual network. |
| 40 | + |
| 41 | +```azurepowershell-interactive |
| 42 | +## Place your virtual network into a variable. ## |
| 43 | +$net = @{ |
| 44 | + Name = 'myVNet' |
| 45 | + ResourceGroupName = 'myResourceGroup' |
| 46 | +} |
| 47 | +$vnet = Get-AzVirtualNetwork @net |
| 48 | +
|
| 49 | +## Place address space into a variable. ## |
| 50 | +$IPAddressRange = '2404:f800:8000:122::/63' |
| 51 | +
|
| 52 | +## Add the address space to the virtual network configuration. ## |
| 53 | +$vnet.AddressSpace.AddressPrefixes.Add($IPAddressRange) |
| 54 | +
|
| 55 | +## Save the configuration to the virtual network. ## |
| 56 | +Set-AzVirtualNetwork -VirtualNetwork $vnet |
| 57 | +``` |
| 58 | + |
| 59 | +Use [Set-AzVirtualNetworkSubnetConfig](/powershell/module/az.network/set-azvirtualnetworksubnetconfig) to add the new IPv6 subnet to the virtual network. |
| 60 | + |
| 61 | +```azurepowershell-interactive |
| 62 | +## Place your virtual network into a variable. ## |
| 63 | +$net = @{ |
| 64 | + Name = 'myVNet' |
| 65 | + ResourceGroupName = 'myResourceGroup' |
| 66 | +} |
| 67 | +$vnet = Get-AzVirtualNetwork @net |
| 68 | +
|
| 69 | +## Create the subnet configuration. ## |
| 70 | +$sub = @{ |
| 71 | + Name = 'myBackendSubnet' |
| 72 | + AddressPrefix = '10.0.0.0/24','2404:f800:8000:122::/64' |
| 73 | + VirtualNetwork = $vnet |
| 74 | +} |
| 75 | +Set-AzVirtualNetworkSubnetConfig @sub |
| 76 | +
|
| 77 | +## Save the configuration to the virtual network. ## |
| 78 | +Set-AzVirtualNetwork -VirtualNetwork $vnet |
| 79 | +``` |
| 80 | + |
| 81 | +## Create IPv6 public IP address |
| 82 | + |
| 83 | +In this section, you'll create a IPv6 public IP address for the virtual machine. |
| 84 | + |
| 85 | +Use [New-AzPublicIpAddress](/powershell/module/az.network/new-azpublicipaddress) to create the public IP address. |
| 86 | + |
| 87 | +```azurepowershell-interactive |
| 88 | +$ip6 = @{ |
| 89 | + Name = 'myPublicIP-IPv6' |
| 90 | + ResourceGroupName = 'myResourceGroup' |
| 91 | + Location = 'eastus2' |
| 92 | + Sku = 'Standard' |
| 93 | + AllocationMethod = 'Static' |
| 94 | + IpAddressVersion = 'IPv6' |
| 95 | + Zone = 1,2,3 |
| 96 | +} |
| 97 | +New-AzPublicIpAddress @ip6 |
| 98 | +``` |
| 99 | +## Add IPv6 configuration to virtual machine |
| 100 | + |
| 101 | +Use [New-AzNetworkInterfaceIpConfig](/powershell/module/az.network/new-aznetworkinterfaceipconfig) to create the IPv6 configuration for the NIC. The **`-Name`** used in the example is **myvm569**. Replace this value with the name of the network interface in your virtual machine. |
| 102 | + |
| 103 | +```azurepowershell-interactive |
| 104 | +## Place your virtual network into a variable. ## |
| 105 | +$net = @{ |
| 106 | + Name = 'myVNet' |
| 107 | + ResourceGroupName = 'myResourceGroup' |
| 108 | +} |
| 109 | +$vnet = Get-AzVirtualNetwork @net |
| 110 | +
|
| 111 | +## Place your virtual network subnet into a variable. ## |
| 112 | +$sub = @{ |
| 113 | + Name = 'myBackendSubnet' |
| 114 | + VirtualNetwork = $vnet |
| 115 | +} |
| 116 | +$subnet = Get-AzVirtualNetworkSubnetConfig @sub |
| 117 | +
|
| 118 | +## Place the IPv6 public IP address you created previously into a variable. ## |
| 119 | +$pip = @{ |
| 120 | + Name = 'myPublicIP-IPv6' |
| 121 | + ResourceGroupName = 'myResourceGroup' |
| 122 | +} |
| 123 | +$publicIP = Get-AzPublicIPAddress @pip |
| 124 | +
|
| 125 | +## Place the network interface into a variable. ## |
| 126 | +$net = @{ |
| 127 | + Name = 'myvm569' |
| 128 | + ResourceGroupName = 'myResourceGroup' |
| 129 | +} |
| 130 | +$nic = Get-AzNetworkInterface @net |
| 131 | +
|
| 132 | +## Create the configuration for the network interface. ## |
| 133 | +$ipc = @{ |
| 134 | + Name = 'Ipv6config' |
| 135 | + Subnet = $subnet |
| 136 | + PublicIpAddress = $publicIP |
| 137 | + PrivateIpAddressVersion = 'IPv6' |
| 138 | +} |
| 139 | +$ipconfig = New-AzNetworkInterfaceIpConfig @ipc |
| 140 | +
|
| 141 | +## Add the IP configuration to the network interface. ## |
| 142 | +$nic.IpConfigurations.Add($ipconfig) |
| 143 | +
|
| 144 | +## Save the configuration to the network interface. ## |
| 145 | +$nic | Set-AzNetworkInterface |
| 146 | +``` |
| 147 | + |
| 148 | +## Next steps |
| 149 | + |
| 150 | +In this article, you learned how to add a dual-stack network to an existing virtual machine. |
| 151 | + |
| 152 | +For more information about IPv6 and IP addresses in Azure, see: |
| 153 | + |
| 154 | +- [Overview of IPv6 for Azure Virtual Network.](ipv6-overview.md) |
| 155 | + |
| 156 | +- [What is Azure Virtual Network IP Services?](ip-services-overview.md) |
| 157 | + |
| 158 | + |
0 commit comments