Skip to content

Commit d504e9c

Browse files
committed
split out secondary IP config as an add section
1 parent f530a4c commit d504e9c

File tree

2 files changed

+68
-24
lines changed

2 files changed

+68
-24
lines changed

articles/load-balancer/load-balancer-multiple-ip-powershell.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Follow the steps below to achieve the scenario outlined in this article:
5454
5555
Then complete [Create a Windows VM](/previous-versions/azure/virtual-machines/scripts/virtual-machines-windows-powershell-sample-create-vm?toc=%2fazure%2fload-balancer%2ftoc.json) steps 6.3 through 6.8.
5656
57-
5. Add a second IP configuration to each of the VMs. Follow the instructions in [Assign multiple IP addresses to virtual machines](../virtual-network/ip-services/virtual-network-multiple-ip-addresses-powershell.md#add) article. Use the following configuration settings:
57+
5. Add a second IP configuration to each of the VMs. Follow the instructions in [Assign multiple IP addresses to virtual machines](../virtual-network/ip-services/virtual-network-multiple-ip-addresses-powershell.md#add-secondary-private-and-public-ip-address) article. Use the following configuration settings:
5858
5959
```powershell
6060
$NicName = "VM1-NIC2"

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

Lines changed: 67 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ New-AzVirtualNetwork @net
9494

9595
## Create public IP addresses
9696

97-
Use [New-AzPublicIpAddress](/powershell/module/az.network/new-azpublicipaddress) to create two public IP addresses.
97+
Use [New-AzPublicIpAddress](/powershell/module/az.network/new-azpublicipaddress) to create a primary public IP address.
9898

9999
```azurepowershell-interactive
100100
$ip4-1 = @{
@@ -107,17 +107,6 @@ $ip4-1 = @{
107107
Zone = 1,2,3
108108
}
109109
New-AzPublicIpAddress @ip4-1
110-
111-
$ip4-2 = @{
112-
Name = 'myPublicIP-2'
113-
ResourceGroupName = 'myResourceGroup'
114-
Location = 'eastus2'
115-
Sku = 'Standard'
116-
AllocationMethod = 'Static'
117-
IpAddressVersion = 'IPv4'
118-
Zone = 1,2,3
119-
}
120-
New-AzPublicIpAddress @ip4-2
121110
```
122111

123112
## Create a network security group
@@ -194,16 +183,6 @@ $IP1 = @{
194183
}
195184
$IP1Config = New-AzNetworkInterfaceIpConfig @IP1
196185
197-
## Create secondary configuration for NIC. ##
198-
$IP2 = @{
199-
Name = 'ipconfig2'
200-
Subnet = $vnet.Subnets[0]
201-
PrivateIpAddressVersion = 'IPv4'
202-
PrivateIpAddress = '10.1.0.5'
203-
PublicIPAddress = $pubIP-2
204-
}
205-
$IP2Config = New-AzNetworkInterfaceIpConfig @IP2
206-
207186
## Create tertiary configuration for NIC. ##
208187
$IP3 = @{
209188
Name = 'ipconfig3'
@@ -219,7 +198,7 @@ $nic = @{
219198
ResourceGroupName = 'myResourceGroup'
220199
Location = 'eastus2'
221200
NetworkSecurityGroup = $nsg
222-
IpConfiguration = $IP1Config,$IP2Config,$IP3Config
201+
IpConfiguration = $IP1Config,$IP3Config
223202
}
224203
New-AzNetworkInterface @nic
225204
```
@@ -281,4 +260,69 @@ $vm = @{
281260
New-AzVM @vm -GenerateSshKey
282261
```
283262

263+
## Add secondary private and public IP address
264+
265+
Use [New-AzPublicIpAddress](/powershell/module/az.network/new-azpublicipaddress) to create a secondary public IP address.
266+
267+
```azurepowershell-interactive
268+
$ip4-2 = @{
269+
Name = 'myPublicIP-2'
270+
ResourceGroupName = 'myResourceGroup'
271+
Location = 'eastus2'
272+
Sku = 'Standard'
273+
AllocationMethod = 'Static'
274+
IpAddressVersion = 'IPv4'
275+
Zone = 1,2,3
276+
}
277+
New-AzPublicIpAddress @ip4-2
278+
```
279+
280+
Use [New-AzNetworkInterfaceIpConfig](/powershell/module/az.network/new-aznetworkinterfaceipconfig) to create the secondary IP configuration for the virtual machine.
281+
282+
```azurepowershell-interactive
283+
## Place the virtual network into a variable. ##
284+
$net = @{
285+
Name = 'myVNet'
286+
ResourceGroupName = 'myResourceGroup'
287+
}
288+
$vnet = Get-AzVirtualNetwork @net
289+
290+
## Place your virtual network subnet into a variable. ##
291+
$sub = @{
292+
Name = 'myBackendSubnet'
293+
VirtualNetwork = $vnet
294+
}
295+
$subnet = Get-AzVirtualNetworkSubnetConfig @sub
296+
297+
## Place the secondary public IP address you created previously into a variable. ##
298+
$pip = @{
299+
Name = 'myPublicIP-2'
300+
ResourceGroupName = 'myResourceGroup'
301+
}
302+
$pubIP-2 = Get-AzPublicIPAddress @pip
303+
304+
## Place the network interface into a variable. ##
305+
$net = @{
306+
Name = 'myNIC1'
307+
ResourceGroupName = 'myResourceGroup'
308+
}
309+
$nic = Get-AzNetworkInterface @net
310+
311+
## Create secondary configuration for NIC. ##
312+
$IP2 = @{
313+
Name = 'ipconfig2'
314+
Subnet = $vnet.Subnets[0]
315+
PrivateIpAddressVersion = 'IPv4'
316+
PrivateIpAddress = '10.1.0.5'
317+
PublicIPAddress = $pubIP-2
318+
}
319+
$IP2Config = New-AzNetworkInterfaceIpConfig @IP2
320+
321+
## Add the IP configuration to the network interface. ##
322+
$nic.IpConfigurations.Add($IP2Config)
323+
324+
## Save the configuration to the network interface. ##
325+
$nic | Set-AzNetworkInterface
326+
```
327+
284328
[!INCLUDE [virtual-network-multiple-ip-addresses-os-config.md](../../../includes/virtual-network-multiple-ip-addresses-os-config.md)]

0 commit comments

Comments
 (0)