Démarrage rapide : Créer une passerelle NAT - Modèle ARMQuickstart: Create a NAT gateway - ARM template

Commencez à utiliser un service NAT de réseau virtuel à l’aide d’un modèle Azure Resource Manager (modèle ARM).Get started with Virtual Network NAT by using an Azure Resource Manager template (ARM template). Ce modèle déploie un réseau virtuel, une ressource de passerelle NAT et une machine virtuelle Ubuntu.This template deploys a virtual network, a NAT gateway resource, and Ubuntu virtual machine. La machine virtuelle Ubuntu est déployée sur un sous-réseau associé à la ressource de passerelle NAT.The Ubuntu virtual machine is deployed to a subnet that is associated with the NAT gateway resource.

Un modèle ARM est un fichier JSON (JavaScript Object Notation) qui définit l’infrastructure et la configuration de votre projet.An ARM template is a JavaScript Object Notation (JSON) file that defines the infrastructure and configuration for your project. Le modèle utilise la syntaxe déclarative.The template uses declarative syntax. Dans la syntaxe déclarative, vous décrivez le déploiement souhaité sans écrire la séquence de commandes de programmation pour créer le déploiement.In declarative syntax, you describe your intended deployment without writing the sequence of programming commands to create the deployment.

Si votre environnement remplit les prérequis et que vous êtes déjà familiarisé avec l’utilisation des modèles ARM, sélectionnez le bouton Déployer sur Azure.If your environment meets the prerequisites and you're familiar with using ARM templates, select the Deploy to Azure button. Le modèle s’ouvre dans le portail Azure.The template will open in the Azure portal.

Déployer sur AzureDeploy to Azure

PrérequisPrerequisites

Si vous n’avez pas d’abonnement Azure, créez un compte gratuit avant de commencer.If you don't have an Azure subscription, create a free account before you begin.

Vérifier le modèleReview the template

Le modèle utilisé dans ce démarrage rapide est tiré des modèles de démarrage rapide Azure.The template used in this quickstart is from Azure Quickstart Templates.

Ce modèle est configuré pour créer les éléments suivants :This template is configured to create a:

  • Réseau virtuelVirtual network
  • Ressource de passerelle NATNAT gateway resource
  • Machine virtuelle UbuntuUbuntu virtual machine

La machine virtuelle Ubuntu est déployée sur un sous-réseau associé à la ressource de passerelle NAT.The Ubuntu VM is deployed to a subnet that's associated with the NAT gateway resource.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "vmname": {
      "defaultValue": "myVM",
      "type": "String",
      "metadata": {
        "description": "Name of the virtual machine"
      }
    },
    "vmsize": {
      "defaultValue": "Standard_D2s_v3",
      "type": "String",
      "metadata": {
        "description": "Size of the virtual machine"
      }
    },
    "vnetname": {
      "defaultValue": "myVnet",
      "type": "String",
      "metadata": {
        "description": "Name of the virtual network"
      }
    },
    "subnetname": {
      "defaultValue": "mySubnet",
      "type": "String",
      "metadata": {
        "description": "Name of the subnet for virtual network"
      }
    },
    "vnetaddressspace": {
      "defaultValue": "192.168.0.0/16",
      "type": "String",
      "metadata": {
        "description": "Address space for virtual network"
      }
    },
    "vnetsubnetprefix": {
      "defaultValue": "192.168.0.0/24",
      "type": "String",
      "metadata": {
        "description": "Subnet prefix for virtual network"
      }
    },
    "natgatewayname": {
      "defaultValue": "myNATgateway",
      "type": "String",
      "metadata": {
        "description": "Name of the NAT gateway"
      }
    },
    "networkinterfacename": {
      "defaultValue": "myvmNIC",
      "type": "String",
      "metadata": {
        "description": "Name of the virtual machine nic"
      }
    },
    "publicipname": {
      "defaultValue": "myPublicIP",
      "type": "String",
      "metadata": {
        "description": "Name of the NAT gateway public IP"
      }
    },
    "nsgname": {
      "defaultValue": "myVMnsg",
      "type": "String",
      "metadata": {
        "description": "Name of the virtual machine NSG"
      }
    },
    "publicipvmname": {
      "defaultValue": "myPublicIPVM",
      "type": "String",
      "metadata": {
        "description": "Name of the virtual machine public IP"
      }
    },
    "publicipprefixname": {
      "defaultValue": "myPublicIPPrefix",
      "type": "String",
      "metadata": {
        "description": "Name of the NAT gateway public IP"
      }
    },
    "adminusername": {
      "type": "String",
      "metadata": {
        "description": "Administrator username for virtual machine"
      }
    },
    "adminpassword": {
      "type": "secureString",
      "metadata": {
        "description": "Administrator password for virtual machine"
      }
    },
    "location": {
      "defaultValue": "[resourceGroup().location]",
      "type": "String",
      "metadata": {
        "description": "Name of resource group"
      }
    }
  },
  "variables": {},
  "resources": [
    {
      "type": "Microsoft.Network/networkSecurityGroups",
      "apiVersion": "2020-06-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": "2020-06-01",
      "name": "[parameters('publicipname')]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "Standard"
      },
      "properties": {
        "publicIPAddressVersion": "IPv4",
        "publicIPAllocationMethod": "Static",
        "idleTimeoutInMinutes": 4
      }
    },
    {
      "type": "Microsoft.Network/publicIPAddresses",
      "apiVersion": "2020-06-01",
      "name": "[parameters('publicipvmname')]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "Standard"
      },
      "properties": {
        "publicIPAddressVersion": "IPv4",
        "publicIPAllocationMethod": "Static",
        "idleTimeoutInMinutes": 4
      }
    },
    {
      "type": "Microsoft.Network/publicIPPrefixes",
      "apiVersion": "2020-06-01",
      "name": "[parameters('publicipprefixname')]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "Standard"
      },
      "properties": {
        "prefixLength": 31,
        "publicIPAddressVersion": "IPv4"
      }
    },
    {
      "type": "Microsoft.Compute/virtualMachines",
      "apiVersion": "2020-06-01",
      "name": "[parameters('vmname')]",
      "location": "[parameters('location')]",
      "dependsOn": [
        "[resourceId('Microsoft.Network/networkInterfaces', parameters('networkinterfacename'))]"
      ],
      "properties": {
        "hardwareProfile": {
          "vmSize": "[parameters('vmsize')]"
        },
        "storageProfile": {
          "imageReference": {
            "publisher": "Canonical",
            "offer": "UbuntuServer",
            "sku": "18.04-LTS",
            "version": "latest"
          },
          "osDisk": {
            "osType": "Linux",
            "name": "[concat(parameters('vmname'), '_disk1')]",
            "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'))]"
            }
          ]
        }
      }
    },
    {
      "type": "Microsoft.Network/virtualNetworks",
      "apiVersion": "2020-06-01",
      "name": "[parameters('vnetname')]",
      "location": "[parameters('location')]",
      "dependsOn": [
        "[resourceId('Microsoft.Network/natGateways', parameters('natgatewayname'))]"
      ],
      "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
      }
    },
    {
      "type": "Microsoft.Network/natGateways",
      "apiVersion": "2020-06-01",
      "name": "[parameters('natgatewayname')]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "Standard"
      },
      "dependsOn": [
        "[resourceId('Microsoft.Network/publicIPAddresses', parameters('publicipname'))]",
        "[resourceId('Microsoft.Network/publicIPPrefixes', parameters('publicipprefixname'))]"
      ],
      "properties": {
        "idleTimeoutInMinutes": 4,
        "publicIpAddresses": [
          {
            "id": "[resourceId('Microsoft.Network/publicIPAddresses', parameters('publicipname'))]"
          }
        ],
        "publicIpPrefixes": [
          {
            "id": "[resourceId('Microsoft.Network/publicIPPrefixes', parameters('publicipprefixname'))]"
          }
        ]
      }
    },
    {
      "type": "Microsoft.Network/virtualNetworks/subnets",
      "apiVersion": "2020-05-01",
      "name": "[concat(parameters('vnetname'), '/mySubnet')]",
      "dependsOn": [
        "[resourceId('Microsoft.Network/virtualNetworks', parameters('vnetname'))]",
        "[resourceId('Microsoft.Network/natGateways', parameters('natgatewayname'))]"
      ],
      "properties": {
        "addressPrefix": "[parameters('vnetsubnetprefix')]",
        "natGateway": {
          "id": "[resourceId('Microsoft.Network/natGateways', parameters('natgatewayname'))]"
        },
        "privateEndpointNetworkPolicies": "Enabled",
        "privateLinkServiceNetworkPolicies": "Enabled"
      }
    },
    {
      "type": "Microsoft.Network/networkInterfaces",
      "apiVersion": "2020-06-01",
      "name": "[parameters('networkinterfacename')]",
      "location": "[parameters('location')]",
      "dependsOn": [
        "[resourceId('Microsoft.Network/publicIPAddresses', parameters('publicipvmname'))]",
        "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('vnetname'), 'mySubnet')]",
        "[resourceId('Microsoft.Network/networkSecurityGroups', parameters('nsgname'))]"
      ],
      "properties": {
        "ipConfigurations": [
          {
            "name": "ipconfig1",
            "properties": {
              "privateIPAddress": "192.168.0.4",
              "privateIPAllocationMethod": "Dynamic",
              "publicIPAddress": {
                "id": "[resourceId('Microsoft.Network/publicIPAddresses', parameters('publicipvmname'))]"
              },
              "subnet": {
                "id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('vnetname'), 'mySubnet')]"
              },
              "primary": true,
              "privateIPAddressVersion": "IPv4"
            }
          }
        ],
        "enableAcceleratedNetworking": false,
        "enableIPForwarding": false,
        "networkSecurityGroup": {
          "id": "[resourceId('Microsoft.Network/networkSecurityGroups', parameters('nsgname'))]"
        }
      }
    }
  ]
}

Neuf ressources Azure sont définies dans le modèle :Nine Azure resources are defined in the template:

Déployer le modèleDeploy the template

Azure CLIAzure CLI

read -p "Enter the location (i.e. westcentralus): " location
resourceGroupName="myResourceGroupNAT"
templateUri="https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-nat-gateway-1-vm/azuredeploy.json"

az group create \
--name $resourceGroupName \
--location $location

az deployment group create \
--resource-group $resourceGroupName \
--template-uri  $templateUri

Azure PowerShellAzure PowerShell

$location = Read-Host -Prompt "Enter the location (i.e. westcentralus)"
$templateUri = "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-nat-gateway-1-vm/azuredeploy.json"

$resourceGroupName = "myResourceGroupNAT"

New-AzResourceGroup -Name $resourceGroupName -Location $location
New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateUri $templateUri

Azure portalAzure portal

Déployer sur AzureDeploy to Azure

Vérifier les ressources déployéesReview deployed resources

  1. Connectez-vous au portail Azure.Sign in to the Azure portal.

  2. Sélectionnez Groupes de ressources dans le volet gauche.Select Resource groups from the left pane.

  3. Sélectionnez le groupe de ressources que vous avez créé dans la section précédente.Select the resource group that you created in the previous section. Le nom du groupe de ressources par défaut est myResourceGroupNAT.The default resource group name is myResourceGroupNAT

  4. Vérifiez que les ressources suivantes ont été créées dans le groupe de ressources :Verify the following resources were created in the resource group:

    Groupe de ressources NAT de réseau virtuel

Nettoyer les ressourcesClean up resources

Azure CLIAzure CLI

Quand vous n’en avez plus besoin, utilisez la commande az group delete pour supprimer le groupe de ressources et toutes les ressources qu’il contient.When no longer needed, you can use the az group delete command to remove the resource group and all resources contained within.

  az group delete \
    --name myResourceGroupNAT

Azure PowerShellAzure PowerShell

Quand vous n’en avez plus besoin, vous pouvez utiliser la commande Remove-AzResourceGroup pour supprimer le groupe de ressources et toutes les ressources qu’il contient.When no longer needed, you can use the Remove-AzResourceGroup command to remove the resource group and all resources contained within.

Remove-AzResourceGroup -Name myResourceGroupNAT

Azure portalAzure portal

Lorsque vous n’en avez plus besoin, supprimez le groupe de ressources, la passerelle NAT et toutes les ressources associées.When no longer needed, delete the resource group, NAT gateway, and all related resources. Sélectionnez le groupe de ressources myResourceGroupNAT qui contient la passerelle NAT, puis sélectionnez Supprimer.Select the resource group myResourceGroupNAT that contains the NAT gateway, and then select Delete.

Étapes suivantesNext steps

Dans le cadre de ce guide de démarrage rapide, vous avez créé les éléments suivants :In this quickstart, you created a:

  • Ressource de passerelle NATNAT gateway resource
  • Réseau virtuelVirtual network
  • Machine virtuelle UbuntuUbuntu virtual machine

La machine virtuelle est déployée sur un sous-réseau de réseau virtuel associé à la passerelle NAT.The virtual machine is deployed to a virtual network subnet associated with the NAT gateway.

Pour en savoir plus sur le service NAT de réseau virtuel et Azure Resource Manager, consultez les articles ci-dessous.To learn more about Virtual Network NAT and Azure Resource Manager, continue to the articles below.