Skip to content

Commit 87091da

Browse files
committed
added nat removal command to powershell
1 parent 095c20b commit 87091da

File tree

1 file changed

+37
-21
lines changed

1 file changed

+37
-21
lines changed

articles/nat-gateway/manage-nat-gateway.md

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ $publicIP = Get-AzPublicIPAddress @pip
177177
$nat = @{
178178
ResourceGroupName = 'test-rg'
179179
Name = 'nat-gateway'
180-
IdleTimeoutInMinutes = '10'
180+
IdleTimeoutInMinutes = '4'
181181
Sku = 'Standard'
182182
Location = 'eastus2'
183183
PublicIpAddress = $publicIP
@@ -206,7 +206,7 @@ Use the [New-AzPublicIpPrefix](/powershell/module/az.network/new-azpublicipprefi
206206
```azurepowershell
207207
## Create public IP prefix for NAT gateway ##
208208
$ip = @{
209-
Name = 'myPublicIPPrefix-NAT'
209+
Name = 'public-ip-prefix-nat'
210210
ResourceGroupName = 'test-rg'
211211
Location = 'eastus2'
212212
Sku = 'Standard'
@@ -227,7 +227,7 @@ $vnet = Get-AzVirtualNetwork @net
227227
228228
## Place the public IP prefix you created previously into a variable. ##
229229
$pip = @{
230-
Name = 'myPublicIPPrefix-NAT'
230+
Name = 'public-ip-prefix-nat'
231231
ResourceGroupName = 'test-rg'
232232
}
233233
$publicIPprefix = Get-AzPublicIPPrefix @pip
@@ -236,7 +236,7 @@ $publicIPprefix = Get-AzPublicIPPrefix @pip
236236
$nat = @{
237237
ResourceGroupName = 'test-rgNAT'
238238
Name = 'nat-gateway'
239-
IdleTimeoutInMinutes = '10'
239+
IdleTimeoutInMinutes = '4'
240240
Sku = 'Standard'
241241
Location = 'eastus2'
242242
PublicIpPrefix = $publicIPprefix
@@ -279,8 +279,7 @@ az network nat gateway create \
279279
--resource-group test-rg \
280280
--name nat-gateway \
281281
--public-ip-addresses public-ip-nat \
282-
--idle-timeout 10
283-
282+
--idle-timeout 4
284283
```
285284

286285
Use [az network vnet subnet update](/cli/azure/network/vnet/subnet#az-network-vnet-subnet-update) to associate the NAT gateway with your virtual network subnet.
@@ -304,7 +303,7 @@ az network public-ip prefix create \
304303
--length 29 \
305304
--resource-group test-rg \
306305
--location eastus2 \
307-
--name myPublicIPprefix-NAT
306+
--name public-ip-prefix-nat
308307
```
309308

310309
Use [az network nat gateway create](/cli/azure/network/nat/gateway#az-network-nat-gateway-create) to create a NAT gateway resource and associate the public IP prefix that you created.
@@ -313,7 +312,7 @@ Use [az network nat gateway create](/cli/azure/network/nat/gateway#az-network-na
313312
az network nat gateway create \
314313
--resource-group test-rg \
315314
--name nat-gateway \
316-
--public-ip-prefixes myPublicIPprefix-NAT \
315+
--public-ip-prefixes public-ip-prefix-nat \
317316
--idle-timeout 10
318317
319318
```
@@ -422,6 +421,9 @@ You can now associate the NAT gateway with a different subnet or virtual network
422421

423422
# [**Azure PowerShell**](#tab/manage-nat-powershell)
424423

424+
Use [Set-AzVirtualNetworkSubnetConfig](/powershell/module/az.network/set-azvirtualnetworksubnetconfig) to remove the NAT gateway association from the subnet by setting the value to $null. Use [Set-AzVirtualNetwork](/powershell/module/az.network/set-azvirtualnetwork) to update the virtual network configuration.
425+
426+
425427
```azurepowershell
426428
# Specify the resource group and NAT gateway name
427429
$resourceGroupName = "test-rg"
@@ -456,6 +458,20 @@ Set-AzVirtualNetwork -VirtualNetwork $virtualNetwork
456458
457459
```
458460

461+
Use [Remove-AzNatGateway](/powershell/module/az.network/remove-aznatgateway) to delete the NAT gateway resource.
462+
463+
```azurepowershell
464+
# Specify the resource group and NAT gateway name
465+
$resourceGroupName = "test-rg"
466+
$natGatewayName = "nat-gateway"
467+
468+
$nat = @{
469+
Name = $natGatewayName
470+
ResourceGroupName = $resourceGroupName
471+
}
472+
Remove-AzNatGateway @nat
473+
```
474+
459475
# [**Azure CLI**](#tab/manage-nat-cli)
460476

461477
Use [az network vnet subnet update](/cli/azure/network/vnet/subnet#az-network-vnet-subnet-update) to remove the NAT gateway from the subnet.
@@ -704,7 +720,7 @@ Complete the following steps to add or remove a public IP prefix from a NAT gate
704720
| Subscription | Select your subscription. |
705721
| Resource group | Select your resource group. This example uses **test-rg**. |
706722
| **Instance details** | |
707-
| Name | Enter *myPublicIPPrefix-NAT*. |
723+
| Name | Enter *public-ip-prefix-nat*. |
708724
| Region | Select your region. This example uses **East US 2**. |
709725
| IP version | Select **IPv4**. |
710726
| Prefix ownership | Select **Microsoft owned**. |
@@ -732,14 +748,14 @@ Complete the following steps to add or remove a public IP prefix from a NAT gate
732748

733749
To add a public IP prefix to the NAT gateway, add it to an array object along with the current IP prefixes. The PowerShell cmdlets replace all the IP prefixes.
734750

735-
In this example, the existing public IP prefix associated with the NAT gateway is named *myPublicIPprefix-NAT*. Replace this value with an array that contains both myPublicIPprefix-NAT and a new IP address prefix. If you have multiple IP prefixes already configured, you must also add them to the array.
751+
In this example, the existing public IP prefix associated with the NAT gateway is named *public-ip-prefix-nat*. Replace this value with an array that contains both public-ip-prefix-nat and a new IP address prefix. If you have multiple IP prefixes already configured, you must also add them to the array.
736752

737753
Use [New-AzPublicIpPrefix](/powershell/module/az.network/new-azpublicipprefix) to create a new public IP prefix for the NAT gateway.
738754

739755
```azurepowershell
740756
## Create public IP prefix for NAT gateway ##
741757
$ip = @{
742-
Name = 'myPublicIPPrefix-NAT2'
758+
Name = 'public-ip-prefix-nat2'
743759
ResourceGroupName = 'test-rg'
744760
Location = 'eastus2'
745761
Sku = 'Standard'
@@ -760,14 +776,14 @@ $nat = Get-AzNatGateway @ng
760776
761777
## Place the existing public IP prefix associated with the NAT gateway into a variable. ##
762778
$ip = @{
763-
Name = 'myPublicIPprefix-NAT'
779+
Name = 'public-ip-prefix-nat'
764780
ResourceGroupName = 'test-rg'
765781
}
766782
$prefixIP1 = Get-AzPublicIPPrefix @ip
767783
768784
## Place the public IP prefix you created previously into a variable. ##
769785
$ip = @{
770-
Name = 'myPublicIPprefix-NAT2'
786+
Name = 'public-ip-prefix-nat2'
771787
ResourceGroupName = 'test-rg'
772788
}
773789
$prefixIP2 = Get-AzPublicIPprefix @ip
@@ -785,7 +801,7 @@ Set-AzNatGateway @nt
785801

786802
### Remove public IP prefix
787803

788-
To remove a public IP prefix from a NAT gateway, create an array object that *doesn't* contain the IP address prefix that you want to remove. For example, you have a NAT gateway configured with two public IP prefixes. You want to remove one of the IP prefixes. The IP prefixes associated with the NAT gateway are named myPublicIPprefix-NAT and myPublicIPprefix-NAT2. To remove myPublicIPprefix-NAT2, create an array object for the PowerShell command that contains *only* myPublicIPprefix-NAT. When you apply the command, the array is reapplied to the NAT gateway, and myPublicIPprefix-NAT is the only prefix associated.
804+
To remove a public IP prefix from a NAT gateway, create an array object that *doesn't* contain the IP address prefix that you want to remove. For example, you have a NAT gateway configured with two public IP prefixes. You want to remove one of the IP prefixes. The IP prefixes associated with the NAT gateway are named public-ip-prefix-nat and public-ip-prefix-nat2. To remove public-ip-prefix-nat2, create an array object for the PowerShell command that contains *only* public-ip-prefix-nat. When you apply the command, the array is reapplied to the NAT gateway, and public-ip-prefix-nat is the only prefix associated.
789805

790806
Use the [Set-AzNatGateway](/powershell/module/az.network/set-aznatgateway) cmdlet to remove a public IP prefix from the NAT gateway.
791807

@@ -799,14 +815,14 @@ $nat = Get-AzNatGateway @ng
799815
800816
## Place the existing public IP prefix associated with the NAT gateway into a variable. ##
801817
$ip = @{
802-
Name = 'myPublicIPprefix-NAT'
818+
Name = 'public-ip-prefix-nat'
803819
ResourceGroupName = 'test-rg'
804820
}
805821
$prefixIP1 = Get-AzPublicIPPrefix @ip
806822
807823
## Place the secondary public IP prefix into a variable. ##
808824
$ip = @{
809-
Name = 'myPublicIPprefix-NAT2'
825+
Name = 'public-ip-prefix-nat2'
810826
ResourceGroupName = 'test-rg'
811827
}
812828
$prefixIP2 = Get-AzPublicIPprefix @ip
@@ -826,7 +842,7 @@ Set-AzNatGateway @nt
826842

827843
### Add public IP prefix
828844

829-
In this example, the existing public IP prefix associated with the NAT gateway is named *myPublicIPprefix-NAT*.
845+
In this example, the existing public IP prefix associated with the NAT gateway is named *public-ip-prefix-nat*.
830846

831847
Use [az network public-ip prefix create](/cli/azure/network/public-ip/prefix#az-network-public-ip-prefix-create) to create a public IP prefix for the NAT gateway.
832848

@@ -835,7 +851,7 @@ az network public-ip prefix create \
835851
--length 29 \
836852
--resource-group test-rg \
837853
--location eastus2 \
838-
--name myPublicIPprefix-NAT2
854+
--name public-ip-prefix-nat2
839855
```
840856

841857
Use [az network nat gateway update](/cli/azure/network/nat/gateway#az-network-nat-gateway-update) to add the public IP prefix that you created to the NAT gateway. The Azure CLI command replaces values. It doesn't add a value. To add the new IP address prefix to the NAT gateway, you must also include any other IP prefixes associated to the NAT gateway.
@@ -844,18 +860,18 @@ Use [az network nat gateway update](/cli/azure/network/nat/gateway#az-network-na
844860
az network nat gateway update \
845861
--name nat-gateway \
846862
--resource-group test-rg \
847-
--public-ip-prefixes myPublicIPprefix-NAT myPublicIPprefix-NAT2
863+
--public-ip-prefixes public-ip-prefix-nat public-ip-prefix-nat2
848864
```
849865

850866
### Remove public IP prefix
851867

852-
Use [az network nat gateway update](/cli/azure/network/nat/gateway#az-network-nat-gateway-update) to remove a public IP prefix from the NAT gateway. The Azure CLI command replaces the values. It doesn't remove a value. To remove a public IP prefix, include any prefix in the command that you wish to keep. Omit the one you want to remove. For example, you have a NAT gateway configured with two public IP prefixes. You want to remove one of the prefixes. The IP prefixes associated with the NAT gateway are named myPublicIPprefix-NAT and myPublicIPprefix-NAT2. To remove myPublicIPprefix-NAT2, omit the name of the IP prefix from the command. The command reapplies the IP prefixes listed in the command to the NAT gateway. It removes any IP address not listed.
868+
Use [az network nat gateway update](/cli/azure/network/nat/gateway#az-network-nat-gateway-update) to remove a public IP prefix from the NAT gateway. The Azure CLI command replaces the values. It doesn't remove a value. To remove a public IP prefix, include any prefix in the command that you wish to keep. Omit the one you want to remove. For example, you have a NAT gateway configured with two public IP prefixes. You want to remove one of the prefixes. The IP prefixes associated with the NAT gateway are named public-ip-prefix-nat and public-ip-prefix-nat2. To remove public-ip-prefix-nat2, omit the name of the IP prefix from the command. The command reapplies the IP prefixes listed in the command to the NAT gateway. It removes any IP address not listed.
853869

854870
```azurecli
855871
az network nat gateway update \
856872
--name nat-gateway \
857873
--resource-group test-rg \
858-
--public-ip-prefixes myPublicIPprefix-NAT
874+
--public-ip-prefixes public-ip-prefix-nat
859875
```
860876

861877
# [**Bicep**](#tab/manage-nat-bicep)

0 commit comments

Comments
 (0)