Skip to content

Commit 86ada0b

Browse files
Merge pull request #221237 from halkazwini/multi-ip-ps
Virtual Network: Freshness: Assign multiple IP addresses to virtual machines using Azure PowerShell
2 parents 0e4b1ff + e76fa90 commit 86ada0b

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

articles/virtual-network/ip-services/virtual-network-multiple-ip-addresses-powershell.md

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
---
2-
title: Multiple IP addresses for Azure virtual machines - Azure PowerShell
2+
title: Assign multiple IP addresses to VMs - Azure PowerShell
33
titleSuffix: Azure Virtual Network
44
description: Learn how to create a virtual machine with multiple IP addresses with Azure PowerShell.
55
services: virtual-network
66
author: asudbring
77
ms.service: virtual-network
88
ms.subservice: ip-services
99
ms.topic: how-to
10-
ms.date: 09/09/2022
10+
ms.date: 12/12/2022
1111
ms.author: allensu
12+
ms.custom: template-how-to, engagement-fy23
1213
---
1314

1415
# Assign multiple IP addresses to virtual machines using Azure PowerShell
@@ -23,34 +24,31 @@ Assigning multiple IP addresses to a VM enables the following capabilities:
2324

2425
* The ability to add any of the private IP addresses for any of the NICs to an Azure Load Balancer back-end pool. In the past, only the primary IP address for the primary NIC could be added to a back-end pool. For more information about load balancing multiple IP configurations, see [Load balancing multiple IP configurations](../../load-balancer/load-balancer-multiple-ip.md?toc=%2fazure%2fvirtual-network%2ftoc.json).
2526

26-
Every NIC attached to a VM has one or more IP configurations associated to it. Each configuration is assigned one static or dynamic private IP address. Each configuration may also have one public IP address resource associated to it. To learn more about IP addresses in Azure, read the [IP addresses in Azure](../../virtual-network/ip-services/public-ip-addresses.md) article.
27+
Every NIC attached to a VM has one or more IP configurations associated to it. Each configuration is assigned one static or dynamic private IP address. Each configuration may also have one public IP address resource associated to it. To learn more about IP addresses in Azure, see [IP addresses in Azure](../../virtual-network/ip-services/public-ip-addresses.md).
2728

2829
> [!NOTE]
29-
> All IP configurations on a single NIC must be associated to the same subnet. If multiple IPs on different subnets are desired, multiple NICs on a VM can be used. To learn more about multiple NICs on a VM in Azure, read the [Create VM with Multiple NICs](../../virtual-machines/windows/multiple-nics.md) article.
30+
> All IP configurations on a single NIC must be associated to the same subnet. If multiple IPs on different subnets are desired, multiple NICs on a VM can be used. To learn more about multiple NICs on a VM in Azure, see [Create VM with Multiple NICs](../../virtual-machines/windows/multiple-nics.md).
3031
3132
There's a limit to how many private IP addresses can be assigned to a NIC. There's also a limit to how many public IP addresses that can be used in an Azure subscription. See the [Azure limits](../../azure-resource-manager/management/azure-subscription-service-limits.md?toc=%2fazure%2fvirtual-network%2ftoc.json#azure-resource-manager-virtual-networking-limits) article for details.
3233

33-
This article explains how to add multiple IP addresses to a virtual machine using the Azure portal.
34+
This article explains how to add multiple IP addresses to a virtual machine using PowerShell.
3435

3536
## Prerequisites
3637

3738
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
3839

39-
- Azure PowerShell installed locally or Azure Cloud Shell.
40+
- PowerShell environment in [Azure Cloud Shell](https://shell.azure.com/powershell) or Azure PowerShell installed locally. To learn more about using PowerShell in Azure Cloud Shell, see [Azure Cloud Shell Quickstart - PowerShell](../../cloud-shell/quickstart-powershell.md).
4041

41-
- Sign in to Azure PowerShell and ensure you've selected the subscription with which you want to use this feature. For more information, see [Sign in with Azure PowerShell](/powershell/azure/authenticate-azureps).
42-
43-
- Ensure your Az. Network module is 4.3.0 or later. To verify the installed module, use the command Get-InstalledModule -Name "Az.Network". If the module requires an update, use the command Update-Module
44-
-Name "Az. Network" if necessary.
42+
- If you choose to install and use PowerShell locally, this article requires the Azure PowerShell module version 5.4.1 or later. Run `Get-InstalledModule -Name Az` to find the installed version. If you need to upgrade, see [Install Azure PowerShell module](/powershell/azure/install-Az-ps). Ensure your Az.Network module is 4.3.0 or later. To verify the installed module, use the command `Get-InstalledModule -Name "Az.Network"`. If the module requires an update, use the command `Update-Module -Name "Az.Network"` if necessary.
4543

46-
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.
44+
- Sign in to Azure PowerShell and ensure you've selected the subscription with which you want to use this feature. For more information, see [Sign in with Azure PowerShell](/powershell/azure/authenticate-azureps).
4745

4846
> [!NOTE]
4947
> Though the steps in this article assigns all IP configurations to a single NIC, you can also assign multiple IP configurations to any NIC in a multi-NIC VM. To learn how to create a VM with multiple NICs, see [Create a VM with multiple NICs](../../virtual-machines/windows/multiple-nics.md).
5048
5149
:::image type="content" source="./media/virtual-network-multiple-ip-addresses-portal/multiple-ipconfigs.png" alt-text="Diagram of network configuration resources created in How-to article.":::
5250

53-
*Figure: Diagram of network configuration resources created in How-to article.*
51+
*Figure: Diagram of network configuration resources created in this How-to article.*
5452

5553
## Create a resource group
5654

@@ -70,7 +68,7 @@ New-AzResourceGroup @rg
7068

7169
In this section, you'll create a virtual network for the virtual machine.
7270

73-
Use [New-AzVirtualNetwork](/powershell/module/az.network/new-azvirtualnetwork) and [New-AzVirtualNetworkSubnetConfig](/powershell/module/az.network/new-azvirtualnetworksubnetconfig) to create a virtual network.
71+
Use [New-AzVirtualNetwork](/powershell/module/az.network/new-azvirtualnetwork) and [New-AzVirtualNetworkSubnetConfig](/powershell/module/az.network/new-azvirtualnetworksubnetconfig) to create a virtual network with one subnet.
7472

7573
```azurepowershell-interactive
7674
## Create backend subnet config ##
@@ -81,18 +79,18 @@ $subnet = @{
8179
$subnetConfig = New-AzVirtualNetworkSubnetConfig @subnet
8280
8381
## Create the virtual network ##
84-
$net = @{
82+
$vnet = @{
8583
Name = 'myVNet'
8684
ResourceGroupName = 'myResourceGroup'
8785
Location = 'eastus2'
8886
AddressPrefix = '10.1.0.0/16'
8987
Subnet = $subnetConfig
9088
}
91-
New-AzVirtualNetwork @net
89+
New-AzVirtualNetwork @vnet
9290
9391
```
9492

95-
## Create primary public IP address
93+
## Create a primary public IP address
9694

9795
Use [New-AzPublicIpAddress](/powershell/module/az.network/new-azpublicipaddress) to create a primary public IP address.
9896

@@ -141,9 +139,9 @@ $nsg = @{
141139
New-AzNetworkSecurityGroup @nsg
142140
```
143141

144-
### Create network interface
142+
## Create a network interface
145143

146-
You'll use [New-AzNetworkInterface](/powershell/module/az.network/new-aznetworkinterface) and [New-AzNetworkInterfaceIpConfig](/powershell/module/az.network/new-aznetworkinterfaceipconfig) to create the network interface for the virtual machine. The public IP addresses and the NSG created previously are associated with the NIC. The network interface is attached to the virtual network you created previously.
144+
Use [New-AzNetworkInterface](/powershell/module/az.network/new-aznetworkinterface) and [New-AzNetworkInterfaceIpConfig](/powershell/module/az.network/new-aznetworkinterfaceipconfig) to create a network interface (NIC) for the virtual machine. The public IP address and network security group created previously are associated with the network interface. The network interface is attached to the virtual network you created previously.
147145

148146
```azurepowershell-interactive
149147
## Place the virtual network into a variable. ##
@@ -167,7 +165,7 @@ $pub1 = @{
167165
}
168166
$pubIP1 = Get-AzPublicIPAddress @pub1
169167
170-
## Create primary configuration for NIC. ##
168+
## Create a primary IP configuration for the network interface. ##
171169
$IP1 = @{
172170
Name = 'ipconfig1'
173171
Subnet = $vnet.Subnets[0]
@@ -176,7 +174,7 @@ $IP1 = @{
176174
}
177175
$IP1Config = New-AzNetworkInterfaceIpConfig @IP1 -Primary
178176
179-
## Create tertiary configuration for NIC. ##
177+
## Create a secondary IP configuration for the network interface. ##
180178
$IP3 = @{
181179
Name = 'ipconfig3'
182180
Subnet = $vnet.Subnets[0]
@@ -185,7 +183,7 @@ $IP3 = @{
185183
}
186184
$IP3Config = New-AzNetworkInterfaceIpConfig @IP3
187185
188-
## Command to create network interface for VM ##
186+
## Command to create a network interface. ##
189187
$nic = @{
190188
Name = 'myNIC1'
191189
ResourceGroupName = 'myResourceGroup'
@@ -199,7 +197,7 @@ New-AzNetworkInterface @nic
199197
> [!NOTE]
200198
> When adding a static IP address, you must specify an unused, valid address on the subnet the NIC is connected to.
201199
202-
### Create virtual machine
200+
## Create a virtual machine
203201

204202
Use the following commands to create the virtual machine:
205203

@@ -301,7 +299,7 @@ $net = @{
301299
}
302300
$nic = Get-AzNetworkInterface @net
303301
304-
## Create secondary configuration for NIC. ##
302+
## Create a secondary IP configuration for the network interface. ##
305303
$IPc2 = @{
306304
Name = 'ipconfig2'
307305
Subnet = $vnet.Subnets[0]
@@ -319,3 +317,9 @@ $nic | Set-AzNetworkInterface
319317
```
320318

321319
[!INCLUDE [virtual-network-multiple-ip-addresses-os-config.md](../../../includes/virtual-network-multiple-ip-addresses-os-config.md)]
320+
321+
## Next steps
322+
323+
- Learn more about [public IP addresses](public-ip-addresses.md) in Azure.
324+
- Learn more about [private IP addresses](private-ip-addresses.md) in Azure.
325+
- Learn how to [Configure IP addresses for an Azure network interface](virtual-network-network-interface-addresses.md?tabs=nic-address-powershell).

0 commit comments

Comments
 (0)