가상 네트워크 서브넷에서 NAT 게이트웨이 리소스를 만들고 제거하는 방법을 알아봅니다. NAT 게이트웨이를 사용하면 Azure Virtual Network 리소스에 대한 아웃바운드 연결을 사용할 수 있습니다. 배포 후 변경된 NAT Gateway와 연결된 공용 IP 주소 및 공용 IP 주소 접두사를 변경할 수 있습니다.
이 문서에서는 NAT 게이트웨이의 다음 측면을 관리하는 방법을 설명합니다.
NAT 게이트웨이를 만들고 기존 서브넷과 연결합니다.
기존 서브넷에서 NAT Gateway를 제거하고 NAT Gateway를 삭제합니다.
공용 IP 주소 또는 공용 IP 접두사를 할당합니다.
필수 조건
이 문서에서 Azure PowerShell을 사용하려면 다음이 필요합니다.
로컬로 설치된 Azure PowerShell 또는 Azure Cloud Shell.
PowerShell을 로컬로 설치하고 사용하도록 선택하는 경우 이 문서에는 Azure PowerShell 모듈 버전 5.4.1 이상이 필요합니다. 설치되어 있는 버전을 확인하려면 Get-Module -ListAvailable Az
을 실행합니다. 업그레이드해야 하는 경우 Azure PowerShell 모듈 설치를 참조하세요.
PowerShell을 로컬로 실행하는 경우 Connect-AzAccount
도 실행하여 Azure와의 연결을 만들어야 합니다.
Az.Network
모듈이 4.3.0 이상인지 확인합니다. 설치된 모듈을 확인하려면 Get-InstalledModule -Name "Az.Network"
명령을 사용합니다. 모듈에 업데이트가 필요한 경우 Update-Module -Name Az.Network
명령을 사용합니다.
Azure PowerShell에 로그인하고 사용하려는 구독을 선택합니다. 자세한 내용은 Azure PowerShell로 로그인을 참조하세요.
이 문서에서 Azure CLI를 사용하려면 다음이 필요합니다.
- Azure CLI, 버전 2.31.0 이상 Azure Cloud Shell은 최신 버전을 사용합니다.
NAT 게이트웨이를 만들고 기존 서브넷과 연결
NAT 게이트웨이 리소스를 만들고 Azure Portal, Azure PowerShell 또는 Azure CLI를 사용하여 기존 서브넷에 추가할 수 있습니다.
Azure Portal에 로그인합니다.
Azure Portal 상단의 검색 상자에 NAT Gateway를 입력합니다. 검색 결과에서 NAT 게이트웨이를 선택합니다.
+ 만들기를 선택합니다.
NAT(Network Address Translation) 게이트웨이 만들기의 기본 사항 탭에서 다음 정보를 입력하거나 선택합니다.
설정 |
값 |
프로젝트 세부 정보 |
|
Subscription |
구독을 선택합니다. |
Resource group |
리소스 그룹을 선택하거나 새로 만들기를 선택하여 새 리소스 그룹을 만듭니다. |
인스턴스 세부 정보 |
|
NAT Gateway 이름 |
nat-gateway를 입력합니다. |
지역 |
지역을 선택합니다. 이 예에서는 미국 동부 2를 사용합니다. |
가용성 영역 |
영역 없음을 선택합니다. NAT 게이트웨이 가용성에 대한 자세한 내용은 NAT 게이트웨이 및 가용성 영역을 참조하세요. |
TCP 유휴 시간 제한(분) |
기본값인 4를 선택합니다. |
아웃바운드 IP 탭을 선택하거나 다음: 아웃바운드 IP를 선택합니다.
기존 공용 IP 주소나 접두사 또는 둘 다를 선택하여 NAT 게이트웨이와 연결하고 아웃바운드 연결을 사용하도록 설정할 수 있습니다.
NAT 게이트웨이에 대한 새 공용 IP를 만들려면 새 공용 IP 주소 만들기를 선택합니다. 이름에 public-ip-nat을 입력합니다. 확인을 선택합니다.
NAT 게이트웨이에 대한 새 공용 IP 접두사를 만들려면 새 공용 IP 접두사 만들기를 선택합니다. 이름에 public-ip-prefix-nat를 입력합니다. 접두사 크기를 선택합니다. 확인을 선택합니다.
서브넷 탭을 선택하거나 다음: 서브넷을 선택합니다.
가상 네트워크를 선택합니다. 이 예제에서는 드롭다운 목록에서 vnet-1을 선택합니다.
서브넷-1 옆에 있는 확인란을 선택합니다.
검토 + 만들기를 선택합니다.
만들기를 선택합니다.
공용 IP 주소
공용 IP 주소로 NAT Gateway를 만들려면 다음 PowerShell 명령을 실행합니다.
New-AzPublicIpAddress cmdlet을 사용하여 NAT Gateway의 공용 IP 주소를 만듭니다.
## Create public IP address for NAT gateway ##
$ip = @{
Name = 'public-ip-nat'
ResourceGroupName = 'test-rg'
Location = 'eastus2'
Sku = 'Standard'
AllocationMethod = 'Static'
}
New-AzPublicIpAddress @ip
New-AzNatGateway cmdlet을 사용하여 NAT Gateway 리소스를 만들고 만든 공용 IP 주소를 연결합니다. Set-AzVirtualNetworkSubnetConfig cmdlet을 사용하여 가상 네트워크 서브넷에 대한 NAT Gateway를 구성합니다.
## Place the virtual network into a variable. ##
$net = @{
Name = 'vnet-1'
ResourceGroupName = 'test-rg'
}
$vnet = Get-AzVirtualNetwork @net
## Place the public IP address you created previously into a variable. ##
$pip = @{
Name = 'public-ip-nat'
ResourceGroupName = 'test-rg'
}
$publicIP = Get-AzPublicIPAddress @pip
## Create NAT gateway resource ##
$nat = @{
ResourceGroupName = 'test-rg'
Name = 'nat-gateway'
IdleTimeoutInMinutes = '4'
Sku = 'Standard'
Location = 'eastus2'
PublicIpAddress = $publicIP
}
$natGateway = New-AzNatGateway @nat
## Create the subnet configuration. ##
$sub = @{
Name = 'subnet-1'
VirtualNetwork = $vnet
NatGateway = $natGateway
AddressPrefix = '10.0.0.0/24'
}
Set-AzVirtualNetworkSubnetConfig @sub
## Save the configuration to the virtual network. ##
$vnet | Set-AzVirtualNetwork
공용 IP 접두사
공용 IP 접두사가 있는 NAT Gateway를 만들려면 다음 명령을 사용합니다.
New-AzPublicIpPrefix cmdlet을 사용하여 NAT Gateway에 대한 공용 IP 접두사를 만듭니다.
## Create public IP prefix for NAT gateway ##
$ip = @{
Name = 'public-ip-prefix-nat'
ResourceGroupName = 'test-rg'
Location = 'eastus2'
Sku = 'Standard'
PrefixLength ='29'
}
New-AzPublicIpPrefix @ip
New-AzNatGateway cmdlet을 사용하여 NAT Gateway 리소스를 만들고 만든 공용 IP 접두사를 연결합니다. Set-AzVirtualNetworkSubnetConfig cmdlet을 사용하여 가상 네트워크 서브넷에 대한 NAT Gateway를 구성합니다.
## Place the virtual network into a variable. ##
$net = @{
Name = 'vnet-1'
ResourceGroupName = 'test-rg'
}
$vnet = Get-AzVirtualNetwork @net
## Place the public IP prefix you created previously into a variable. ##
$pip = @{
Name = 'public-ip-prefix-nat'
ResourceGroupName = 'test-rg'
}
$publicIPprefix = Get-AzPublicIPPrefix @pip
## Create NAT gateway resource ##
$nat = @{
ResourceGroupName = 'test-rgNAT'
Name = 'nat-gateway'
IdleTimeoutInMinutes = '4'
Sku = 'Standard'
Location = 'eastus2'
PublicIpPrefix = $publicIPprefix
}
$natGateway = New-AzNatGateway @nat
## Create the subnet configuration. ##
$sub = @{
Name = 'subnet-1'
VirtualNetwork = $vnet
NatGateway = $natGateway
AddressPrefix = '10.0.0.0/24'
}
Set-AzVirtualNetworkSubnetConfig @sub
## Save the configuration to the virtual network. ##
$vnet | Set-AzVirtualNetwork
공용 IP 주소
공용 IP 주소로 NAT Gateway를 만들려면 다음 명령을 사용합니다.
az network public-ip create를 사용하여 NAT 게이트웨이에 대한 공용 IP 주소를 만듭니다.
az network public-ip create \
--resource-group test-rg \
--location eastus2 \
--name public-ip-nat \
--sku standard
az network nat gateway create를 사용하여 NAT Gateway 리소스를 만들고 만든 공용 IP 주소를 연결합니다.
az network nat gateway create \
--resource-group test-rg \
--name nat-gateway \
--public-ip-addresses public-ip-nat \
--idle-timeout 4
az network vnet subnet update를 사용하여 NAT 게이트웨이를 가상 네트워크 서브넷과 연결합니다.
az network vnet subnet update \
--resource-group test-rg \
--vnet-name vnet-1 \
--name subnet-1 \
--nat-gateway nat-gateway
공용 IP 접두사
공용 IP 접두사가 있는 NAT Gateway를 만들려면 다음 명령을 사용합니다.
az network public-ip prefix create를 사용하여 NAT 게이트웨이에 대한 공용 IP 접두사를 만듭니다.
az network public-ip prefix create \
--length 29 \
--resource-group test-rg \
--location eastus2 \
--name public-ip-prefix-nat
az network nat gateway create를 사용하여 NAT Gateway 리소스를 만들고 만든 공용 IP 접두사를 연결합니다.
az network nat gateway create \
--resource-group test-rg \
--name nat-gateway \
--public-ip-prefixes public-ip-prefix-nat \
--idle-timeout 10
az network vnet subnet update를 사용하여 NAT 게이트웨이를 가상 네트워크 서브넷과 연결합니다.
az network vnet subnet update \
--resource-group test-rg \
--vnet-name vnet-1 \
--name subnet-1 \
--nat-gateway nat-gateway
@description('Name of the NAT gateway')
param natgatewayname string = 'nat-gateway'
@description('Name of the NAT gateway public IP')
param publicipname string = 'public-ip-nat'
@description('Name of resource group')
param location string = resourceGroup().location
var existingVNetName = 'vnet-1'
var existingSubnetName = 'subnet-1'
resource vnet 'Microsoft.Network/virtualNetworks@2023-05-01' existing = {
name: existingVNetName
}
output vnetid string = vnet.id
resource publicip 'Microsoft.Network/publicIPAddresses@2023-06-01' = {
name: publicipname
location: location
sku: {
name: 'Standard'
}
properties: {
publicIPAddressVersion: 'IPv4'
publicIPAllocationMethod: 'Static'
idleTimeoutInMinutes: 4
}
}
resource natgateway 'Microsoft.Network/natGateways@2023-06-01' = {
name: natgatewayname
location: location
sku: {
name: 'Standard'
}
properties: {
idleTimeoutInMinutes: 4
publicIpAddresses: [
{
id: publicip.id
}
]
}
}
output natgatewayid string = natgateway.id
resource updatedsubnet01 'Microsoft.Network/virtualNetworks/subnets@2023-06-01' = {
parent: vnet
name: existingSubnetName
properties: {
addressPrefix: vnet.properties.subnets[0].properties.addressPrefix
natGateway: {
id: natgateway.id
}
}
}
기존 서브넷에서 NAT 게이트웨이 제거 및 리소스 삭제
기존 서브넷에서 NAT 게이트웨이를 제거하려면 다음 단계를 완료합니다.
Azure Portal에 로그인합니다.
Azure Portal 상단의 검색 상자에 NAT Gateway를 입력합니다. 검색 결과에서 NAT 게이트웨이를 선택합니다.
nat-gateway를 선택합니다.
설정에서 서브넷을 선택합니다.
모든 서브넷에서 NAT 게이트웨이를 제거하려면 연결 해제를 선택합니다.
여러 서브넷 중 하나에서만 NAT 게이트웨이를 제거하려면 서브넷 옆에 있는 확인란의 선택을 취소하고 저장을 선택합니다.
이제 NAT 게이트웨이를 구독의 다른 서브넷 또는 가상 네트워크에 연결할 수 있습니다. NAT 게이트웨이 리소스를 삭제하려면 다음 단계를 완료합니다.
Azure Portal 상단의 검색 상자에 NAT Gateway를 입력합니다. 검색 결과에서 NAT 게이트웨이를 선택합니다.
nat-gateway를 선택합니다.
삭제를 선택합니다.
예를 선택합니다.
Set-AzVirtualNetworkSubnetConfig를 사용하여 값을 $null 설정하여 서브넷에서 NAT 게이트웨이 연결을 제거합니다. Set-AzVirtualNetwork를 사용하여 가상 네트워크 구성을 업데이트합니다.
# Specify the resource group and NAT gateway name
$resourceGroupName = "test-rg"
# Specify the virtual network name and subnet name
$virtualNetworkName = "vnet-1"
$subnetName = "subnet-1"
# Get the virtual network
$vnet = @{
Name = $virtualNetworkName
ResourceGroupName = $resourceGroupName
}
$virtualNetwork = Get-AzVirtualNetwork @vnet
# Get the subnet
$subnet = $virtualNetwork.Subnets | Where-Object {$_.Name -eq $subnetName}
# Remove the NAT gateway association from the subnet
$subnet.NatGateway = $null
# Update the subnet configuration
$subConfig = @{
Name = $subnetName
VirtualNetwork = $virtualNetwork
AddressPrefix = $subnet.AddressPrefix
}
Set-AzVirtualNetworkSubnetConfig @subConfig
# Update the virtual network
Set-AzVirtualNetwork -VirtualNetwork $virtualNetwork
Remove-AzNatGateway를 사용하여 NAT 게이트웨이 리소스를 삭제합니다.
# Specify the resource group and NAT gateway name
$resourceGroupName = "test-rg"
$natGatewayName = "nat-gateway"
$nat = @{
Name = $natGatewayName
ResourceGroupName = $resourceGroupName
}
Remove-AzNatGateway @nat
az network vnet subnet update를 사용하여 서브넷에서 NAT 게이트웨이를 제거합니다.
az network vnet subnet update \
--resource-group test-rg \
--vnet-name vnet-1 \
--name subnet-1 \
--remove natGateway
az network nat gateway delete를 사용하여 NAT 게이트웨이 리소스를 삭제합니다.
az network nat gateway delete \
--name nat-gateway \
--resource-group test-rg
@description('Name of resource group')
param location string = resourceGroup().location
var existingVNetName = 'vnet-1'
var existingSubnetName = 'subnet-1'
resource vnet 'Microsoft.Network/virtualNetworks@2023-05-01' existing = {
name: existingVNetName
}
output vnetid string = vnet.id
resource updatedsubnet01 'Microsoft.Network/virtualNetworks/subnets@2023-06-01' = {
parent: vnet
name: existingSubnetName
properties: {
addressPrefix: vnet.properties.subnets[0].properties.addressPrefix
}
}
참고 항목
NAT Gateway를 삭제할 때 연결된 공용 IP 주소 또는 접두사는 삭제되지 않습니다.
공용 IP 주소 추가 또는 제거
NAT 게이트웨이에서 공용 IP 주소를 추가하거나 제거하려면 다음 단계를 완료합니다.
Azure Portal에 로그인합니다.
Azure Portal 상단의 검색 상자에 공용 IP 주소를 입력합니다. 검색 결과에서 공용 IP 주소를 선택합니다.
만들기를 실행합니다.
공용 IP 주소 만들기에 다음 정보를 입력합니다.
설정 |
값 |
Subscription |
구독을 선택합니다. |
Resource group |
리소스 그룹을 선택합니다. 이 예제에서는 test-rg를 사용합니다. |
지역 |
지역을 선택합니다. 이 예에서는 미국 동부 2를 사용합니다. |
속성 |
public-ip-nat2를 입력 합니다. |
IP 버전 |
IPv4를 선택합니다. |
SKU |
표준을 선택합니다. |
가용성 영역 |
기본값인 영역 중복을 선택합니다. |
계층 |
지역을 선택합니다. |
검토 + 생성를 선택한 다음, 생성를 선택합니다.
Azure Portal 상단의 검색 상자에 NAT Gateway를 입력합니다. 검색 결과에서 NAT 게이트웨이를 선택합니다.
nat-gateway를 선택합니다.
설정에서 아웃바운드 IP를 선택합니다.
NAT 게이트웨이와 연결된 IP 주소 및 접두사가 표시됩니다. 공용 IP 주소 옆에 있는 변경을 선택합니다.
공용 IP 주소 옆에 있는 IP 주소 드롭다운을 선택합니다. NAT Gateway에 추가하기 위해 만든 IP 주소를 선택합니다. 주소를 제거하려면 선택을 취소합니다.
확인을 선택합니다.
저장을 선택합니다.
공용 IP 주소 추가
NAT Gateway에 공용 IP 주소를 추가하려면 현재 IP 주소와 함께 배열 개체에 추가합니다. PowerShell cmdlet은 모든 주소를 바꿉니다.
이 예제에서는 NAT 게이트웨이와 연결된 기존 IP 주소의 이름을 public-ip-nat로 지정 합니다. 이 값을 public-ip-nat 및 새 IP 주소를 모두 포함하는 배열로 대체합니다. 여러 IP 주소가 이미 구성되어 있는 경우 해당 주소도 배열에 추가해야 합니다.
New-AzPublicIpAddress를 사용하여 NAT 게이트웨이에 대한 새 IP 주소를 만듭니다.
## Create public IP address for NAT gateway ##
$ip = @{
Name = 'public-ip-nat2'
ResourceGroupName = 'test-rg'
Location = 'eastus2'
Sku = 'Standard'
AllocationMethod = 'Static'
}
New-AzPublicIpAddress @ip
Set-AzNatGateway를 사용하여 NAT 게이트웨이에 공용 IP 주소를 추가합니다.
## Place NAT gateway into a variable. ##
$ng = @{
Name = 'nat-gateway'
ResourceGroupName = 'test-rg'
}
$nat = Get-AzNatGateway @ng
## Place the existing public IP address associated with the NAT gateway into a variable. ##
$ip = @{
Name = 'public-ip-nat'
ResourceGroupName = 'test-rg'
}
$publicIP1 = Get-AzPublicIPaddress @ip
## Place the public IP address you created previously into a variable. ##
$ip = @{
Name = 'public-ip-nat2'
ResourceGroupName = 'test-rg'
}
$publicIP2 = Get-AzPublicIPaddress @ip
## Place the public IP address variables into an array. ##
$pipArray = $publicIP1,$publicIP2
## Add the IP address to the NAT gateway. ##
$nt = @{
NatGateway = $nat
PublicIpAddress = $pipArray
}
Set-AzNatGateway @nt
공용 IP 주소 제거
NAT Gateway에서 공용 IP를 제거하려면 제거하려는 IP 주소를 포함하지 않는 배열 개체를 만듭니다. 예를 들어 두 개의 공용 IP 주소로 구성된 NAT 게이트웨이가 있습니다. IP 주소 중 하나를 제거하려고 합니다. NAT 게이트웨이와 연결된 IP 주소의 이름은 public-ip-nat 및 public-ip-nat2입니다. public-ip-nat2를 제거하려면 public-ip-nat만 포함하는 PowerShell 명령에 대한 배열 개체를 만듭니다. 명령을 적용하면 배열이 NAT 게이트웨이에 다시 적용되고 public-ip-nat는 연결된 유일한 공용 IP 주소입니다.
Set-AzNatGateway를 사용하여 NAT 게이트웨이에서 공용 IP 주소를 제거합니다.
## Place NAT gateway into a variable. ##
$ng = @{
Name = 'nat-gateway'
ResourceGroupName = 'test-rg'
}
$nat = Get-AzNatGateway @ng
## Place the existing public IP address associated with the NAT gateway into a variable. ##
$ip = @{
Name = 'public-ip-nat'
ResourceGroupName = 'test-rg'
}
$publicIP1 = Get-AzPublicIPaddress @ip
## Place the second public IP address into a variable. ##
$ip = @{
Name = 'public-ip-nat2'
ResourceGroupName = 'test-rg'
}
$publicIP2 = Get-AzPublicIPAddress @ip
## Place ONLY the public IP you wish to keep in the array. ##
$pipArray = $publicIP1
## Add the public IP address to the NAT gateway. ##
$nt = @{
NatGateway = $nat
PublicIpAddress = $pipArray
}
Set-AzNatGateway @nt
공용 IP 주소 추가
이 예제에서는 NAT 게이트웨이와 연결된 기존 공용 IP 주소의 이름을 public-ip-nat로 지정 합니다.
az network public-ip create를 사용하여 NAT 게이트웨이에 대한 새 IP 주소를 만듭니다.
az network public-ip create \
--resource-group test-rg \
--location eastus2 \
--name public-ip-nat2 \
--sku standard
az network nat gateway update를 사용하여 만든 공용 IP 주소를 NAT Gateway에 추가합니다. Azure CLI 명령은 값을 바꿉니다. 새로운 값을 추가하지 않습니다. NAT Gateway에 새 IP 주소를 추가하려면 NAT Gateway와 연결된 다른 모든 IP 주소도 포함해야 합니다.
az network nat gateway update \
--name nat-gateway \
--resource-group test-rg \
--public-ip-addresses public-ip-nat public-ip-nat2
공용 IP 주소 제거
az network nat gateway update를 사용하여 NAT 게이트웨이에서 공용 IP 주소를 제거합니다. Azure CLI 명령은 값을 바꿉니다. 값을 제거하지 않습니다. 공용 IP 주소를 제거하려면 유지하려는 명령에 IP 주소를 포함합니다. 제거할 값을 생략합니다. 예를 들어 두 개의 공용 IP 주소로 구성된 NAT 게이트웨이가 있습니다. IP 주소 중 하나를 제거하려고 합니다. NAT 게이트웨이와 연결된 IP 주소의 이름은 public-ip-nat 및 public-ip-nat2입니다. public-ip-nat2를 제거하려면 명령에서 IP 주소의 이름을 생략합니다. 이 명령은 명령에 나열된 IP 주소를 NAT Gateway에 다시 적용합니다. 목록에 없는 모든 IP 주소를 제거합니다.
az network nat gateway update \
--name nat-gateway \
--resource-group test-rg \
--public-ip-addresses public-ip-nat
Azure Portal, Azure PowerShell 또는 Azure CLI를 사용하여 NAT 게이트웨이에서 공용 IP 주소를 추가하거나 제거합니다.
공용 IP 접두사 추가 또는 제거
NAT 게이트웨이에서 공용 IP 접두사를 추가하거나 제거하려면 다음 단계를 완료합니다.
Azure Portal에 로그인합니다.
Azure Portal 상단의 검색 상자에 공용 IP 접두사를 입력합니다. 검색 결과에서 공용 IP 접두사를 선택합니다.
만들기를 실행합니다.
공용 IP 접두사 만들기의 기본 탭에 다음 정보를 입력합니다.
설정 |
값 |
프로젝트 세부 정보 |
|
Subscription |
구독을 선택합니다. |
Resource group |
리소스 그룹을 선택합니다. 이 예제에서는 test-rg를 사용합니다. |
인스턴스 세부 정보 |
|
속성 |
public-ip-prefix-nat를 입력 합니다. |
지역 |
지역을 선택합니다. 이 예에서는 미국 동부 2를 사용합니다. |
IP 버전 |
IPv4를 선택합니다. |
접두사 소유권 |
Microsoft 소유를 선택합니다. |
접두사 크기 |
접두사 크기를 선택합니다. 이 예에서는 /28(주소 16개)을 사용합니다. |
검토 + 생성를 선택한 다음, 생성를 선택합니다.
Azure Portal 상단의 검색 상자에 NAT Gateway를 입력합니다. 검색 결과에서 NAT 게이트웨이를 선택합니다.
nat-gateway를 선택합니다.
설정에서 아웃바운드 IP를 선택합니다.
이 페이지에는 NAT Gateway와 연결된 IP 주소 및 접두사가 표시됩니다. 공용 IP 접두사 옆에 있는 변경을 선택합니다.
공용 IP 접두사 옆에 있는 드롭다운 상자를 선택합니다. NAT Gateway에 접두사를 추가하기 위해 만든 IP 주소 접두사를 선택합니다. 접두사를 제거하려면 선택을 취소합니다.
확인을 선택합니다.
저장을 선택합니다.
공용 IP 접두사 추가
NAT Gateway에 공용 IP 접두사를 추가하려면 현재 IP 접두사와 함께 배열 개체에 추가합니다. PowerShell cmdlet은 모든 IP 접두사를 바꿉니다.
이 예제에서는 NAT 게이트웨이와 연결된 기존 공용 IP 접두사 이름을 public-ip-prefix-nat로 지정 합니다. 이 값을 public-ip-prefix-nat 및 새 IP 주소 접두사를 모두 포함하는 배열로 대체합니다. 여러 IP 접두사가 이미 구성되어 있는 경우 배열에도 추가해야 합니다.
New-AzPublicIpPrefix를 사용하여 NAT 게이트웨이에 대한 새 공용 IP 접두사를 만듭니다.
## Create public IP prefix for NAT gateway ##
$ip = @{
Name = 'public-ip-prefix-nat2'
ResourceGroupName = 'test-rg'
Location = 'eastus2'
Sku = 'Standard'
PrefixLength = '29'
}
New-AzPublicIpPrefix @ip
Set-AzNatGateway를 사용하여 NAT 게이트웨이에 공용 IP 접두사를 추가합니다.
## Place NAT gateway into a variable. ##
$ng = @{
Name = 'nat-gateway'
ResourceGroupName = 'test-rg'
}
$nat = Get-AzNatGateway @ng
## Place the existing public IP prefix associated with the NAT gateway into a variable. ##
$ip = @{
Name = 'public-ip-prefix-nat'
ResourceGroupName = 'test-rg'
}
$prefixIP1 = Get-AzPublicIPPrefix @ip
## Place the public IP prefix you created previously into a variable. ##
$ip = @{
Name = 'public-ip-prefix-nat2'
ResourceGroupName = 'test-rg'
}
$prefixIP2 = Get-AzPublicIPprefix @ip
## Place the public IP address variables into an array. ##
$preArray = $prefixIP1,$prefixIP2
## Add the IP address prefix to the NAT gateway. ##
$nt = @{
NatGateway = $nat
PublicIpPrefix = $preArray
}
Set-AzNatGateway @nt
공용 IP 접두사 제거
NAT Gateway에서 공용 IP 접두사를 제거하려면 제거하려는 IP 주소 접두사를 포함하지 않는 배열 개체를 만듭니다. 예를 들어 두 개의 공용 IP 접두사로 구성된 NAT 게이트웨이가 있습니다. IP 접두사 중 하나를 제거하려고 합니다. NAT 게이트웨이와 연결된 IP 접두사는 public-ip-prefix-nat 및 public-ip-prefix-nat2로 명명됩니다. public-ip-prefix-nat2를 제거하려면 public-ip-prefix-nat만 포함하는 PowerShell 명령에 대한 배열 개체를 만듭니다. 명령을 적용하면 배열이 NAT 게이트웨이에 다시 적용되고 public-ip-prefix-nat가 연결된 유일한 접두사입니다.
Set-AzNatGateway cmdlet을 사용하여 NAT Gateway에서 공용 IP 접두사를 제거합니다.
## Place NAT gateway into a variable. ##
$ng = @{
Name = 'nat-gateway'
ResourceGroupName = 'test-rg'
}
$nat = Get-AzNatGateway @ng
## Place the existing public IP prefix associated with the NAT gateway into a variable. ##
$ip = @{
Name = 'public-ip-prefix-nat'
ResourceGroupName = 'test-rg'
}
$prefixIP1 = Get-AzPublicIPPrefix @ip
## Place the secondary public IP prefix into a variable. ##
$ip = @{
Name = 'public-ip-prefix-nat2'
ResourceGroupName = 'test-rg'
}
$prefixIP2 = Get-AzPublicIPprefix @ip
## Place ONLY the prefix you wish to keep in the array. DO NOT ADD THE SECONDARY VARIABLE ##
$preArray = $prefixIP1
## Add the IP address prefix to the NAT gateway. ##
$nt = @{
NatGateway = $nat
PublicIpPrefix = $preArray
}
Set-AzNatGateway @nt
공용 IP 접두사 추가
이 예제에서는 NAT 게이트웨이와 연결된 기존 공용 IP 접두사 이름을 public-ip-prefix-nat로 지정 합니다.
az network public-ip prefix create를 사용하여 NAT 게이트웨이에 대한 공용 IP 접두사를 만듭니다.
az network public-ip prefix create \
--length 29 \
--resource-group test-rg \
--location eastus2 \
--name public-ip-prefix-nat2
az network nat gateway update를 사용하여 만든 공용 IP 접두사를 NAT Gateway에 추가합니다. Azure CLI 명령은 값을 바꿉니다. 값을 추가하지 않습니다. NAT Gateway에 새 IP 주소 접두사를 추가하려면 NAT Gateway에 연결된 다른 IP 접두사도 포함해야 합니다.
az network nat gateway update \
--name nat-gateway \
--resource-group test-rg \
--public-ip-prefixes public-ip-prefix-nat public-ip-prefix-nat2
공용 IP 접두사 제거
az network nat gateway update를 사용하여 NAT 게이트웨이에서 공용 IP 접두사를 제거합니다. Azure CLI 명령은 값을 바꿉니다. 값을 제거하지 않습니다. 공용 IP 접두사를 제거하려면 유지하려는 명령에 접두사를 포함합니다. 제거하려는 항목을 생략합니다. 예를 들어 두 개의 공용 IP 접두사로 구성된 NAT 게이트웨이가 있습니다. 접두사 중 하나를 제거하려고 합니다. NAT 게이트웨이와 연결된 IP 접두사는 public-ip-prefix-nat 및 public-ip-prefix-nat2로 명명됩니다. public-ip-prefix-nat2를 제거하려면 명령에서 IP 접두사 이름을 생략합니다. 이 명령은 명령에 나열된 IP 접두사를 NAT Gateway에 다시 적용합니다. 목록에 없는 모든 IP 주소를 제거합니다.
az network nat gateway update \
--name nat-gateway \
--resource-group test-rg \
--public-ip-prefixes public-ip-prefix-nat
Azure Portal, Azure PowerShell 또는 Azure CLI를 사용하여 NAT 게이트웨이에서 공용 IP 접두사를 추가하거나 제거합니다.
다음 단계
Azure Virtual Network NAT 및 해당 기능에 대한 자세한 내용은 다음 문서를 참조하세요.