You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Create a NAT gateway and associate it with an existing virtual network.
431
-
432
-
Azure NAT Gateway V2 adds a feature that allows you to associate a NAT gateway with an entire virtual network instead of a specific subnet.
433
-
434
-
You can create a NAT gateway resource and add it to an existing virtual network by using the Azure portal, Azure PowerShell, or Azure CLI.
435
-
436
-
# [**Azure portal**](#tab/manage-nat-portal)
437
-
438
-
1. Sign in to the [Azure portal](https://portal.azure.com).
439
-
440
-
1. In the search box at the top of the Azure portal, enter **NAT gateway**. Select **NAT gateways** in the search results.
441
-
442
-
1. Select **Create**.
443
-
444
-
1. Enter or select the following information in the **Basics** tab of **Create network address translation (NAT) gateway**.
445
-
446
-
| Setting | Value |
447
-
| ------- | ----- |
448
-
|**Project details**||
449
-
| Subscription | Select your subscription. |
450
-
| Resource group | Select **test-rg** or your resource group. |
451
-
|**Instance details**||
452
-
| NAT gateway name | Enter **nat-gateway**. |
453
-
| Region | Select your region. This example uses **West US**. |
454
-
| SKU | Select **Standard V2**. |
455
-
| TCP idle timeout (minutes) | Leave the default of **4**. |
456
-
457
-
1. Select **Next**.
458
-
459
-
1. In the **Outbound IP** tab, select **+ Add public IP addresses or prefixes**.
460
-
461
-
1. In **Add public IP addresses or prefixes**, select **Public IP addresses**. You can select an existing public IP address or create a new one.
462
-
463
-
- To create a new public IP for the NAT gateway, select **Create a new public IP address**. Enter **public-ip-nat** in **Name**. Select **OK**.
464
-
465
-
- To create a new public IP prefix for the NAT gateway, select **Create a new public IP prefix**. Enter **public-ip-prefix-nat** in **Name**. Select a **Prefix size**. Select **OK**.
466
-
467
-
1. Select **Save**.
468
-
469
-
1. Select the **Networking** tab, or select **Next**.
470
-
471
-
1. Select your virtual network. In this example, select **vnet-1** in the dropdown list.
472
-
473
-
1. Select the checkbox **Default to all subnets**.
Use [New-AzNatGateway](/powershell/module/az.network/new-aznatgateway) to create the NAT gateway resource.
482
-
483
-
### Public IP address
484
-
485
-
Use the [New-AzPublicIpAddress](/powershell/module/az.network/new-azpublicipaddress) cmdlet to create a public IP address for the NAT gateway.
486
-
487
-
```azurepowershell
488
-
## Create public IP address for NAT gateway ##
489
-
$ip = @{
490
-
Name = 'public-ip-nat'
491
-
ResourceGroupName = 'test-rg'
492
-
Location = 'eastus'
493
-
Sku = 'StandardV2'
494
-
AllocationMethod = 'Static'
495
-
IpAddressVersion = 'IPv4'
496
-
Zone = 1,2,3
497
-
}
498
-
New-AzPublicIpAddress @ip
499
-
```
500
-
501
-
```azurepowershell
502
-
## Place the existing virtual network into a variable
503
-
$net = @{
504
-
Name = 'vnet-1'
505
-
ResourceGroupName = 'test-rg'
506
-
}
507
-
$vnet = Get-AzVirtualNetwork @net
508
-
509
-
## Place the public IP address you created previously into a variable. ##
510
-
$pip = @{
511
-
Name = 'public-ip-nat'
512
-
ResourceGroupName = 'test-rg'
513
-
}
514
-
$publicIPIPv4 = Get-AzPublicIpAddress @pip
515
-
516
-
## Create NAT gateway resource ##
517
-
$nat = @{
518
-
ResourceGroupName = 'test-rg'
519
-
Name = 'nat-gateway'
520
-
IdleTimeoutInMinutes = '4'
521
-
PublicIpAddress = $publicIPIPv4
522
-
Sku = 'StandardV2'
523
-
Location = 'eastus'
524
-
SourceVirtualNetwork = $vnet
525
-
Zone = 1,2,3
526
-
}
527
-
$natGateway = New-AzNatGateway @nat
528
-
```
529
-
530
-
### Public IP prefix
531
-
532
-
Use the [New-AzPublicIpPrefix](/powershell/module/az.network/new-azpublicipprefix) cmdlet to create a public IP prefix for the NAT gateway.
533
-
534
-
```azurepowershell
535
-
## Create public IP prefix for NAT gateway ##
536
-
$ip = @{
537
-
Name = 'public-ip-prefix-nat'
538
-
ResourceGroupName = 'test-rg'
539
-
Location = 'eastus'
540
-
Sku = 'StandardV2'
541
-
PrefixLength = '31'
542
-
IpAddressVersion = 'IPv4'
543
-
Zone = 1,2,3
544
-
}
545
-
New-AzPublicIpPrefix @ip
546
-
```
547
-
548
-
```azurepowershell
549
-
## Place the existing virtual network into a variable
550
-
$net = @{
551
-
Name = 'vnet-1'
552
-
ResourceGroupName = 'test-rg'
553
-
}
554
-
$vnet = Get-AzVirtualNetwork @net
555
-
556
-
## Place the public IP prefix you created previously into a variable. ##
557
-
$pip = @{
558
-
Name = 'public-ip-prefix-nat'
559
-
ResourceGroupName = 'test-rg'
560
-
}
561
-
$publicIPIPv4prefix = Get-AzPublicIPPrefix @pip
562
-
563
-
## Create NAT gateway resource ##
564
-
$nat = @{
565
-
ResourceGroupName = 'test-rg'
566
-
Name = 'nat-gateway'
567
-
IdleTimeoutInMinutes = '4'
568
-
PublicIpPrefix = $publicIPIPv4prefix
569
-
Sku = 'StandardV2'
570
-
Location = 'eastus'
571
-
SourceVirtualNetwork = $vnet
572
-
Zone = 1,2,3
573
-
}
574
-
$natGateway = New-AzNatGateway @nat
575
-
```
576
-
577
-
# [**Azure CLI**](#tab/manage-nat-cli)
578
-
579
-
### Public IP address
580
-
581
-
Use [az network public-ip create](/cli/azure/network/public-ip#az-network-public-ip-create) to create a StandardV2 public IP address for the NAT gateway.
582
-
583
-
```azurecli
584
-
az network public-ip create \
585
-
--resource-group test-rg \
586
-
--name public-ip-nat \
587
-
--location eastus \
588
-
--sku StandardV2 \
589
-
--allocation-method Static \
590
-
--version IPv4 \
591
-
--zone 1 2 3
592
-
```
593
-
594
-
Use [az network nat gateway create](/cli/azure/network/nat/gateway#az-network-nat-gateway-create) to create the NAT gateway resource and associate it with the virtual network.
595
-
596
-
```azurecli
597
-
az network nat gateway create \
598
-
--resource-group test-rg \
599
-
--name nat-gateway \
600
-
--location eastus \
601
-
--public-ip-addresses public-ip-nat \
602
-
--idle-timeout 4 \
603
-
--sku StandardV2 \
604
-
--zone 1 2 3 \
605
-
--vnet vnet-1
606
-
```
607
-
608
-
### Public IP prefix
609
-
610
-
Use [az network public-ip prefix create](/cli/azure/network/public-ip/prefix#az-network-public-ip-prefix-create) to create a StandardV2 public IP prefix for the NAT gateway.
611
-
612
-
```azurecli
613
-
az network public-ip prefix create \
614
-
--resource-group test-rg \
615
-
--name public-ip-prefix-nat \
616
-
--location eastus \
617
-
--length 31 \
618
-
--sku StandardV2 \
619
-
--version IPv4 \
620
-
--zone 1 2 3
621
-
```
622
-
623
-
Use [az network nat gateway create](/cli/azure/network/nat/gateway#az-network-nat-gateway-create) to create the NAT gateway resource and associate it with the virtual network.
624
-
625
-
```azurecli
626
-
az network nat gateway create \
627
-
--resource-group test-rg \
628
-
--name nat-gateway \
629
-
--location eastus \
630
-
--public-ip-prefixes public-ip-prefix-nat \
631
-
--idle-timeout 4 \
632
-
--sku StandardV2 \
633
-
--zone 1 2 3 \
634
-
--vnet vnet-1
635
-
```
636
-
637
-
# [**Bicep**](#tab/manage-nat-bicep)
638
-
639
-
> [!NOTE]
640
-
> Bicep support for virtual network-level NAT gateway association isn't currently available. Use the Azure portal, Azure PowerShell, or Azure CLI to associate a NAT gateway with a virtual network.
641
-
642
-
---
643
-
644
426
## Remove a NAT gateway from an existing subnet and delete the resource
645
427
646
428
To remove a NAT gateway from an existing subnet, complete the following steps.
## Remove a NAT gateway from an existing virtual network and delete the NAT gateway
771
-
772
-
To remove a NAT gateway from an existing virtual network, complete the following steps.
773
-
774
-
# [**Azure portal**](#tab/manage-nat-portal)
775
-
776
-
1. Sign in to the [Azure portal](https://portal.azure.com).
777
-
778
-
1. In the search box at the top of the Azure portal, enter **NAT gateway**. Select **NAT gateways** in the search results.
779
-
780
-
1. Select **nat-gateway**.
781
-
782
-
1. Select **Networking**.
783
-
784
-
1. To remove NAT gateway from the network, select **X Disassociate**.
785
-
786
-
You can now associate the NAT gateway with a different subnet or virtual network in your subscription. To delete the NAT gateway resource, complete the following steps.
787
-
788
-
1. In the search box at the top of the Azure portal, enter **NAT gateway**. Select **NAT gateways** in the search results.
Use [Set-AzNatGateway](/powershell/module/az.network/set-aznatgateway) to remove the NAT gateway association from the virtual network by setting the value to $null.
799
-
800
-
```azurepowershell
801
-
## Place NAT gateway into a variable. ##
802
-
$ng = @{
803
-
Name = 'nat-gateway'
804
-
ResourceGroupName = 'test-rg'
805
-
}
806
-
$nat = Get-AzNatGateway @ng
807
-
808
-
## Remove the NAT gateway association from the virtual network. ##
809
-
$nat.SourceVirtualNetwork = $null
810
-
Set-AzNatGateway @nat
811
-
```
812
-
813
-
Use [Remove-AzNatGateway](/powershell/module/az.network/remove-aznatgateway) to delete the NAT gateway resource.
814
-
815
-
```azurepowershell
816
-
# Specify the resource group and NAT gateway name
817
-
$nat = @{
818
-
Name = 'nat-gateway'
819
-
ResourceGroupName = 'test-rg'
820
-
}
821
-
Remove-AzNatGateway @nat
822
-
```
823
-
824
-
# [**Azure CLI**](#tab/manage-nat-cli)
825
-
826
-
Use [az network nat gateway update](/cli/azure/network/nat/gateway#az-network-nat-gateway-update) to remove the NAT gateway association from the virtual network.
827
-
828
-
```azurecli
829
-
az network nat gateway update \
830
-
--name nat-gateway \
831
-
--resource-group test-rg \
832
-
--vnet ""
833
-
```
834
-
835
-
Use [az network nat gateway delete](/cli/azure/network/nat/gateway#az-network-nat-gateway-delete) to delete the NAT gateway resource.
836
-
837
-
```azurecli
838
-
az network nat gateway delete \
839
-
--name nat-gateway \
840
-
--resource-group test-rg
841
-
```
842
-
843
-
# [**Bicep**](#tab/manage-nat-bicep)
844
-
845
-
> [!NOTE]
846
-
> Bicep support for virtual network-level NAT gateway association isn't currently available. Use the Azure portal, Azure PowerShell, or Azure CLI to remove a NAT gateway from a virtual network.
847
-
848
-
---
849
-
850
552
> [!NOTE]
851
553
> When you delete a NAT gateway, the public IP address or prefix associated with it isn't deleted.
0 commit comments