Quickstart: Create a private endpoint by using Azure PowerShell
Get started with Azure Private Link by using a private endpoint to connect securely to an Azure web app.
In this quickstart, you'll create a private endpoint for an Azure web app and then create and deploy a virtual machine (VM) to test the private connection.
You can create private endpoints for a variety of Azure services, such as Azure SQL and Azure Storage.
Prerequisites
An Azure account with an active subscription. If you don't already have an Azure account, create an account for free.
An Azure web app with a PremiumV2-tier or higher app service plan, deployed in your Azure subscription.
For more information and an example, see Quickstart: Create an ASP.NET Core web app in Azure.
For a detailed tutorial on creating a web app and an endpoint, see Tutorial: Connect to a web app by using a private endpoint.
If you choose to install and use PowerShell locally, this article requires the Azure PowerShell module version 5.4.1 or later. To find the installed version, run Get-Module -ListAvailable Az. If you need to upgrade, see Install the Azure PowerShell module. If you're running PowerShell locally, you also need to run Connect-AzAccount to create a connection with Azure.
Create a resource group
An Azure resource group is a logical container where Azure resources are deployed and managed.
Create a resource group with New-AzResourceGroup:
New-AzResourceGroup -Name 'CreatePrivateEndpointQS-rg' -Location 'eastus'
Create a virtual network and bastion host
First, you'll create a virtual network, subnet, and bastion host.
You'll use the bastion host to connect securely to the VM for testing the private endpoint.
Create a virtual network and bastion host with:
Configure the back-end subnet.
$subnetConfig = New-AzVirtualNetworkSubnetConfig -Name myBackendSubnet -AddressPrefix 10.0.0.0/24Create the Azure Bastion subnet:
$bastsubnetConfig = New-AzVirtualNetworkSubnetConfig -Name AzureBastionSubnet -AddressPrefix 10.0.1.0/24Create the virtual network:
$parameters1 = @{ Name = 'MyVNet' ResourceGroupName = 'CreatePrivateEndpointQS-rg' Location = 'eastus' AddressPrefix = '10.0.0.0/16' Subnet = $subnetConfig, $bastsubnetConfig } $vnet = New-AzVirtualNetwork @parameters1Create the public IP address for the bastion host:
$parameters2 = @{ Name = 'myBastionIP' ResourceGroupName = 'CreatePrivateEndpointQS-rg' Location = 'eastus' Sku = 'Standard' AllocationMethod = 'Static' } $publicip = New-AzPublicIpAddress @parameters2Create the bastion host:
$parameters3 = @{ ResourceGroupName = 'CreatePrivateEndpointQS-rg' Name = 'myBastion' PublicIpAddress = $publicip VirtualNetwork = $vnet } New-AzBastion @parameters3
It can take a few minutes for the Azure Bastion host to deploy.
Create a test virtual machine
Next, create a VM that you can use to test the private endpoint.
Create the VM by using:
Get the server admin credentials and password:
$cred = Get-CredentialGet the virtual network configuration:
$vnet = Get-AzVirtualNetwork -Name myVNet -ResourceGroupName CreatePrivateEndpointQS-rgCreate a network interface for the VM:
$parameters1 = @{ Name = 'myNicVM' ResourceGroupName = 'CreatePrivateEndpointQS-rg' Location = 'eastus' Subnet = $vnet.Subnets[0] } $nicVM = New-AzNetworkInterface @parameters1Configure the VM:
$parameters2 = @{ VMName = 'myVM' VMSize = 'Standard_DS1_v2' } $parameters3 = @{ ComputerName = 'myVM' Credential = $cred } $parameters4 = @{ PublisherName = 'MicrosoftWindowsServer' Offer = 'WindowsServer' Skus = '2019-Datacenter' Version = 'latest' } $vmConfig = New-AzVMConfig @parameters2 | Set-AzVMOperatingSystem -Windows @parameters3 | Set-AzVMSourceImage @parameters4 | Add-AzVMNetworkInterface -Id $nicVM.IdCreate the VM:
New-AzVM -ResourceGroupName 'CreatePrivateEndpointQS-rg' -Location 'eastus' -VM $vmConfig
Note
Azure provides a default outbound access IP for VMs that either aren't assigned a public IP address or are in the back-end pool of an internal basic Azure load balancer. The default outbound access IP mechanism provides an outbound IP address that isn't configurable.
For more information, see Default outbound access in Azure.
The default outbound access IP is disabled when either a public IP address is assigned to the VM or the VM is placed in the back-end pool of a standard load balancer, with or without outbound rules. If an Azure Virtual Network network address translation (NAT) gateway resource is assigned to the subnet of the virtual machine, the default outbound access IP is disabled.
VMs that are created by virtual machine scale sets in flexible orchestration mode don't have default outbound access.
For more information about outbound connections in Azure, see Use source network address translation (SNAT) for outbound connections.
Create a private endpoint
Create a private endpoint and connection by using:
Place the web app into a variable. Replace <webapp-resource-group-name> with the resource group name of your web app, and replace <your-webapp-name> with your web app name.
$webapp = Get-AzWebApp -ResourceGroupName <webapp-resource-group-name> -Name <your-webapp-name>Create the private endpoint connection:
$parameters1 = @{ Name = 'myConnection' PrivateLinkServiceId = $webapp.ID GroupID = 'sites' } $privateEndpointConnection = New-AzPrivateLinkServiceConnection @parameters1Place the virtual network into a variable:
$vnet = Get-AzVirtualNetwork -ResourceGroupName 'CreatePrivateEndpointQS-rg' -Name 'myVNet'Disable the private endpoint network policy:
$vnet.Subnets[0].PrivateEndpointNetworkPolicies = "Disabled" $vnet | Set-AzVirtualNetworkCreate the private endpoint:
$parameters2 = @{ ResourceGroupName = 'CreatePrivateEndpointQS-rg' Name = 'myPrivateEndpoint' Location = 'eastus' Subnet = $vnet.Subnets[0] PrivateLinkServiceConnection = $privateEndpointConnection } New-AzPrivateEndpoint @parameters2
Configure the private DNS zone
Create and configure the private DNS zone by using:
Place the virtual network into a variable:
$vnet = Get-AzVirtualNetwork -ResourceGroupName 'CreatePrivateEndpointQS-rg' -Name 'myVNet'Create the private DNS zone:
$parameters1 = @{ ResourceGroupName = 'CreatePrivateEndpointQS-rg' Name = 'privatelink.azurewebsites.net' } $zone = New-AzPrivateDnsZone @parameters1Create a DNS network link:
$parameters2 = @{ ResourceGroupName = 'CreatePrivateEndpointQS-rg' ZoneName = 'privatelink.azurewebsites.net' Name = 'myLink' VirtualNetworkId = $vnet.Id } $link = New-AzPrivateDnsVirtualNetworkLink @parameters2Configure the DNS zone:
$parameters3 = @{ Name = 'privatelink.azurewebsites.net' PrivateDnsZoneId = $zone.ResourceId } $config = New-AzPrivateDnsZoneConfig @parameters3Create the DNS zone group:
$parameters4 = @{ ResourceGroupName = 'CreatePrivateEndpointQS-rg' PrivateEndpointName = 'myPrivateEndpoint' Name = 'myZoneGroup' PrivateDnsZoneConfig = $config } New-AzPrivateDnsZoneGroup @parameters4
Test connectivity with the private endpoint
Finally, use the VM you created in the previous step to connect to the SQL server across the private endpoint.
Sign in to the Azure portal.
On the left pane, select Resource groups.
Select CreatePrivateEndpointQS-rg.
Select myVM.
On the overview page for myVM, select Connect, and then select Bastion.
Select the blue Use Bastion button.
Enter the username and password that you used when you created the VM.
After you've connected, open PowerShell on the server.
Enter
nslookup <your-webapp-name>.azurewebsites.net. Replace <your-webapp-name> with the name of the web app that you created earlier. You'll receive a message that's similar to the following:Server: UnKnown Address: 168.63.129.16 Non-authoritative answer: Name: mywebapp8675.privatelink.azurewebsites.net Address: 10.0.0.5 Aliases: mywebapp8675.azurewebsites.netA private IP address of 10.0.0.5 is returned for the web app name. This address is in the subnet of the virtual network that you created earlier.
In the bastion connection to myVM, open your web browser.
Enter the URL of your web app, https://<your-webapp-name>.azurewebsites.net.
If your web app hasn't been deployed, you'll get the following default web app page:
Close the connection to myVM.
Clean up resources
When you're done using the private endpoint and the VM, use Remove-AzResourceGroup to remove the resource group and all the resources within it:
Remove-AzResourceGroup -Name CreatePrivateEndpointQS-rg -Force
What you've learned
In this quickstart, you created:
- A virtual network and bastion host
- A virtual machine
- A private endpoint for an Azure web app
You used the VM to securely test connectivity to the web app across the private endpoint.
Next steps
For more information about the services that support private endpoints, see:
Povratne informacije
Pošalјite i prikažite povratne informacije za