리소스 그룹 만들기
az group create를 사용하여 리소스 그룹을 만듭니다. Azure 리소스 그룹은 Azure 리소스가 배포 및 관리되는 논리적 컨테이너입니다.
az group create \
--name test-rg \
--___location eastus2
NAT 게이트웨이 만들기
이 섹션에서는 NAT 게이트웨이와 지원 리소스를 만듭니다.
공용 IP 주소 만들기
인터넷에 액세스하려면 NAT 게이트웨이에 대한 하나 이상의 공용 IP 주소가 필요합니다.
az network public-ip create를 사용하여 공용 IP 주소 리소스를 만듭니다.
az network public-ip create \
--resource-group test-rg \
--name public-ip-nat \
--sku Standard \
--allocation-method Static \
--___location eastus2 \
--zone 1 2 3
NAT 게이트웨이 리소스 만들기
az network nat gateway create를 사용하여 NAT 게이트웨이 리소스를 만듭니다. NAT 게이트웨이는 이전 단계에서 만든 공용 IP 주소를 사용합니다. 유휴 시간 제한은 10분으로 설정됩니다.
az network nat gateway create \
--resource-group test-rg \
--name nat-gateway \
--public-ip-addresses public-ip-nat \
--idle-timeout 10
가상 네트워크 및 서브넷 만들기
az network vnet create를 사용하여 서브넷-1이라는 서브넷을 사용하여 vnet-1이라는 가상 네트워크를 만듭니다. 가상 네트워크의 IP 주소 공간은 10.0.0.0/16입니다. 가상 네트워크 내의 서브넷은 10.0.0.0/24입니다.
az network vnet create \
--resource-group test-rg \
--name vnet-1 \
--address-prefix 10.0.0.0/16 \
--subnet-name subnet-1 \
--subnet-prefixes 10.0.0.0/24
Azure Bastion 서브넷 만들기
az network vnet subnet create를 사용하여 AzureBastionSubnet이라는 Azure Bastion 서브넷을 만듭니다.
az network vnet subnet create \
--name AzureBastionSubnet \
--resource-group test-rg \
--vnet-name vnet-1 \
--address-prefix 10.0.1.0/26
NAT 게이트웨이를 서브넷에 연결
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
Bastion 호스트에 대한 공용 IP 주소 만들기
az network public-ip create를 사용하여 Bastion 호스트에 대한 공용 IP 주소를 만듭니다.
az network public-ip create \
--resource-group test-rg \
--name public-ip \
--sku Standard \
--___location eastus2 \
--zone 1 2 3
Bastion 호스트 만들기
az network bastion create를 사용하여 Azure Bastion 호스트를 만듭니다.
az network bastion create \
--name bastion \
--public-ip-address public-ip \
--resource-group test-rg \
--vnet-name vnet-1 \
--___location eastus2
Bastion 호스트를 배포하는 데 몇 분 정도 걸릴 수 있습니다. 다음 섹션으로 이동하기 전에 Bastion 호스트가 배포되기를 기다립니다.
가상 머신 만들기
vm-1이라는 가상 머신을 만들어 NAT 게이트웨이를 테스트하고 아웃바운드 연결의 공용 IP 주소를 확인합니다.
az vm create 사용:
az vm create \
--resource-group test-rg \
--name vm-1 \
--image Ubuntu2204 \
--admin-username azureuser \
--authentication-type password \
--public-ip-address "" \
--subnet subnet-1 \
--vnet-name vnet-1
다음 섹션으로 이동하기 전에 가상 머신 만들기가 완료될 때까지 기다립니다.
Azure Resource Manager 템플릿은 프로젝트에 대한 인프라 및 구성을 정의하는 JSON(JavaScript Object Notation) 파일입니다. 템플릿은 선언적 구문을 사용합니다. 배포를 만들기 위한 프로그래밍 명령의 시퀀스를 작성하지 않고 의도하는 배포를 설명합니다.
환경이 필수 조건을 충족하고 ARM 템플릿 사용에 익숙한 경우 Azure에 배포 단추를 선택합니다. 그러면 Azure Portal에서 템플릿이 열립니다.
템플릿 검토
이 빠른 시작에서 사용되는 템플릿은 Azure 빠른 시작 템플릿에서 나온 것입니다.
이 템플릿은 다음을 만들도록 구성되어 있습니다.
가상 네트워크
NAT 게이트웨이 리소스
Ubuntu 가상 머신
Ubuntu 가상 머신은 NAT 게이트웨이 리소스와 연결된 서브넷에 배포됩니다.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.25.53.49325",
"templateHash": "15583664434476061565"
}
},
"parameters": {
"vmname": {
"type": "string",
"defaultValue": "vm-1",
"metadata": {
"description": "Name of the virtual machine"
}
},
"vmsize": {
"type": "string",
"defaultValue": "Standard_D2s_v3",
"metadata": {
"description": "Size of the virtual machine"
}
},
"vnetname": {
"type": "string",
"defaultValue": "vnet-1",
"metadata": {
"description": "Name of the virtual network"
}
},
"subnetname": {
"type": "string",
"defaultValue": "subnet-1",
"metadata": {
"description": "Name of the subnet for virtual network"
}
},
"vnetaddressspace": {
"type": "string",
"defaultValue": "10.0.0.0/16",
"metadata": {
"description": "Address space for virtual network"
}
},
"vnetsubnetprefix": {
"type": "string",
"defaultValue": "10.0.0.0/24",
"metadata": {
"description": "Subnet prefix for virtual network"
}
},
"natgatewayname": {
"type": "string",
"defaultValue": "nat-gateway",
"metadata": {
"description": "Name of the NAT gateway"
}
},
"networkinterfacename": {
"type": "string",
"defaultValue": "nic-1",
"metadata": {
"description": "Name of the virtual machine nic"
}
},
"publicipname": {
"type": "string",
"defaultValue": "public-ip-nat",
"metadata": {
"description": "Name of the NAT gateway public IP"
}
},
"nsgname": {
"type": "string",
"defaultValue": "nsg-1",
"metadata": {
"description": "Name of the virtual machine NSG"
}
},
"adminusername": {
"type": "string",
"metadata": {
"description": "Administrator username for virtual machine"
}
},
"adminpassword": {
"type": "securestring",
"metadata": {
"description": "Administrator password for virtual machine"
}
},
"___location": {
"type": "string",
"defaultValue": "[resourceGroup().___location]",
"metadata": {
"description": "Name of resource group"
}
}
},
"resources": [
{
"type": "Microsoft.Network/networkSecurityGroups",
"apiVersion": "2021-05-01",
"name": "[parameters('nsgname')]",
"___location": "[parameters('___location')]",
"properties": {
"securityRules": [
{
"name": "SSH",
"properties": {
"protocol": "Tcp",
"sourcePortRange": "*",
"destinationPortRange": "22",
"sourceAddressPrefix": "*",
"destinationAddressPrefix": "*",
"access": "Allow",
"priority": 300,
"direction": "Inbound"
}
}
]
}
},
{
"type": "Microsoft.Network/publicIPAddresses",
"apiVersion": "2021-05-01",
"name": "[parameters('publicipname')]",
"___location": "[parameters('___location')]",
"sku": {
"name": "Standard"
},
"properties": {
"publicIPAddressVersion": "IPv4",
"publicIPAllocationMethod": "Static",
"idleTimeoutInMinutes": 4
}
},
{
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2021-11-01",
"name": "[parameters('vmname')]",
"___location": "[parameters('___location')]",
"properties": {
"hardwareProfile": {
"vmSize": "[parameters('vmsize')]"
},
"storageProfile": {
"imageReference": {
"publisher": "Canonical",
"offer": "0001-com-ubuntu-server-jammy",
"sku": "22_04-lts-gen2",
"version": "latest"
},
"osDisk": {
"osType": "Linux",
"name": "[format('{0}_disk1', parameters('vmname'))]",
"createOption": "FromImage",
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Premium_LRS"
},
"diskSizeGB": 30
}
},
"osProfile": {
"computerName": "[parameters('vmname')]",
"adminUsername": "[parameters('adminusername')]",
"adminPassword": "[parameters('adminpassword')]",
"linuxConfiguration": {
"disablePasswordAuthentication": false,
"provisionVMAgent": true
},
"allowExtensionOperations": true
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', parameters('networkinterfacename'))]"
}
]
}
},
"dependsOn": [
"[resourceId('Microsoft.Network/networkInterfaces', parameters('networkinterfacename'))]"
]
},
{
"type": "Microsoft.Network/virtualNetworks",
"apiVersion": "2021-05-01",
"name": "[parameters('vnetname')]",
"___location": "[parameters('___location')]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"[parameters('vnetaddressspace')]"
]
},
"subnets": [
{
"name": "[parameters('subnetname')]",
"properties": {
"addressPrefix": "[parameters('vnetsubnetprefix')]",
"natGateway": {
"id": "[resourceId('Microsoft.Network/natGateways', parameters('natgatewayname'))]"
},
"privateEndpointNetworkPolicies": "Enabled",
"privateLinkServiceNetworkPolicies": "Enabled"
}
}
],
"enableDdosProtection": false,
"enableVmProtection": false
},
"dependsOn": [
"[resourceId('Microsoft.Network/natGateways', parameters('natgatewayname'))]"
]
},
{
"type": "Microsoft.Network/natGateways",
"apiVersion": "2021-05-01",
"name": "[parameters('natgatewayname')]",
"___location": "[parameters('___location')]",
"sku": {
"name": "Standard"
},
"properties": {
"idleTimeoutInMinutes": 4,
"publicIpAddresses": [
{
"id": "[resourceId('Microsoft.Network/publicIPAddresses', parameters('publicipname'))]"
}
]
},
"dependsOn": [
"[resourceId('Microsoft.Network/publicIPAddresses', parameters('publicipname'))]"
]
},
{
"type": "Microsoft.Network/virtualNetworks/subnets",
"apiVersion": "2021-05-01",
"name": "[format('{0}/{1}', parameters('vnetname'), 'subnet-1')]",
"properties": {
"addressPrefix": "[parameters('vnetsubnetprefix')]",
"natGateway": {
"id": "[resourceId('Microsoft.Network/natGateways', parameters('natgatewayname'))]"
},
"privateEndpointNetworkPolicies": "Enabled",
"privateLinkServiceNetworkPolicies": "Enabled"
},
"dependsOn": [
"[resourceId('Microsoft.Network/natGateways', parameters('natgatewayname'))]",
"[resourceId('Microsoft.Network/virtualNetworks', parameters('vnetname'))]"
]
},
{
"type": "Microsoft.Network/networkInterfaces",
"apiVersion": "2021-05-01",
"name": "[parameters('networkinterfacename')]",
"___location": "[parameters('___location')]",
"properties": {
"ipConfigurations": [
{
"name": "ipconfig-1",
"properties": {
"privateIPAddress": "10.0.0.4",
"privateIPAllocationMethod": "Dynamic",
"subnet": {
"id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('vnetname'), 'subnet-1')]"
},
"primary": true,
"privateIPAddressVersion": "IPv4"
}
}
],
"enableAcceleratedNetworking": false,
"enableIPForwarding": false,
"networkSecurityGroup": {
"id": "[resourceId('Microsoft.Network/networkSecurityGroups', parameters('nsgname'))]"
}
},
"dependsOn": [
"[resourceId('Microsoft.Network/networkSecurityGroups', parameters('nsgname'))]",
"[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('vnetname'), 'subnet-1')]"
]
}
],
"outputs": {
"___location": {
"type": "string",
"value": "[parameters('___location')]"
},
"name": {
"type": "string",
"value": "[parameters('natgatewayname')]"
},
"resourceGroupName": {
"type": "string",
"value": "[resourceGroup().name]"
},
"resourceId": {
"type": "string",
"value": "[resourceId('Microsoft.Network/natGateways', parameters('natgatewayname'))]"
}
}
}
템플릿에는 아홉 개의 Azure 리소스가 정의되어 있습니다.
템플릿 배포
입구
배포된 리소스 검토
Azure Portal에 로그인합니다.
왼쪽 패널에서 리소스 그룹 을 선택합니다.
이전 섹션에서 만든 리소스 그룹을 선택합니다. 기본 리소스 그룹 이름은 myResourceGroupNAT입니다.
다음 리소스가 리소스 그룹에서 만들어졌는지 확인합니다.
PowerShell
$___location = Read-Host -Prompt "Enter the ___location (i.e. westcentralus)"
$templateUri = "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.network/nat-gateway-1-vm/azuredeploy.json"
$resourceGroupName = "myResourceGroupNAT"
New-AzResourceGroup -Name $resourceGroupName -Location $___location
New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateUri $templateUri
Azure 커맨드 라인 인터페이스 (CLI)
read -p "Enter the ___location (i.e. westcentralus): " ___location
resourceGroupName="myResourceGroupNAT"
templateUri="https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.network/nat-gateway-1-vm/azuredeploy.json"
az group create \
--name $resourceGroupName \
--___location $___location
az deployment group create \
--resource-group $resourceGroupName \
--template-uri $templateUri