Tutorial: Connect to an Azure SQL server using an Azure Private Endpoint using the Azure portal
Artikkel
Azure Private endpoint is the fundamental building block for Private Link in Azure. It enables Azure resources, like virtual machines (VMs), to privately and securely communicate with Private Link resources such as Azure SQL server.
In this tutorial, you learn how to:
Create a virtual network and bastion host.
Create a virtual machine.
Create an Azure SQL server and private endpoint.
Test connectivity to the SQL server private endpoint.
If you don't have an Azure subscription, create a free account before you begin.
Create a virtual network and an Azure Bastion host
The following procedure creates a virtual network with a resource subnet, an Azure Bastion subnet, and a Bastion host:
In the portal, search for and select Virtual networks.
On the Virtual networks page, select + Create.
On the Basics tab of Create virtual network, enter, or select the following information:
Setting
Value
Project details
Subscription
Select your subscription.
Resource group
Select Create new. Enter test-rg for the name. Select OK.
Instance details
Name
Enter vnet-1.
Region
Select East US 2.
Select Next to proceed to the Security tab.
In the Azure Bastion section, select Enable Azure Bastion.
Bastion uses your browser to connect to VMs in your virtual network over Secure Shell (SSH) or Remote Desktop Protocol (RDP) by using their private IP addresses. The VMs don't need public IP addresses, client software, or special configuration. For more information, see What is Azure Bastion?.
Märkus
Hourly pricing starts from the moment that Bastion is deployed, regardless of outbound data usage. For more information, see Pricing and SKUs. If you're deploying Bastion as part of a tutorial or test, we recommend that you delete this resource after you finish using it.
In Azure Bastion, enter or select the following information:
Setting
Value
Azure Bastion host name
Enter bastion.
Azure Bastion public IP address
Select Create a public IP address. Enter public-ip-bastion in Name. Select OK.
Select Next to proceed to the IP Addresses tab.
In the address space box in Subnets, select the default subnet.
In Edit subnet, enter or select the following information:
Setting
Value
Subnet purpose
Leave the default of Default.
Name
Enter subnet-1.
IPv4
IPv4 address range
Leave the default of 10.0.0.0/16.
Starting address
Leave the default of 10.0.0.0.
Size
Leave the default of /24 (256 addresses).
Select Save.
Select Review + create at the bottom of the window. When validation passes, select Create.
Create test virtual machine
The following procedure creates a test virtual machine (VM) named vm-1 in the virtual network.
In the portal, search for and select Virtual machines.
In Virtual machines, select + Create, then Azure virtual machine.
On the Basics tab of Create a virtual machine, enter or select the following information:
Setting
Value
Project details
Subscription
Select your subscription.
Resource group
Select test-rg.
Instance details
Virtual machine name
Enter vm-1.
Region
Select East US 2.
Availability options
Select No infrastructure redundancy required.
Security type
Leave the default of Standard.
Image
Select Ubuntu Server 22.04 LTS - x64 Gen2.
VM architecture
Leave the default of x64.
Size
Select a size.
Administrator account
Authentication type
Select Password.
Username
Enter azureuser.
Password
Enter a password.
Confirm password
Reenter the password.
Inbound port rules
Public inbound ports
Select None.
Select the Networking tab at the top of the page.
Enter or select the following information in the Networking tab:
Setting
Value
Network interface
Virtual network
Select vnet-1.
Subnet
Select subnet-1 (10.0.0.0/24).
Public IP
Select None.
NIC network security group
Select Advanced.
Configure network security group
Select Create new. Enter nsg-1 for the name. Leave the rest at the defaults and select OK.
Leave the rest of the settings at the defaults and select Review + create.
Review the settings and select Create.
Märkus
Virtual machines in a virtual network with a bastion host don't need public IP addresses. Bastion provides the public IP, and the VMs use private IPs to communicate within the network. You can remove the public IPs from any VMs in bastion hosted virtual networks. For more information, see Dissociate a public IP address from an Azure VM.
Märkus
Azure provides a default outbound access IP for VMs that either aren't assigned a public IP address or are in the backend pool of an internal basic Azure load balancer. The default outbound access IP mechanism provides an outbound IP address that isn't configurable.
The default outbound access IP is disabled when one of the following events happens:
A public IP address is assigned to the VM.
The VM is placed in the backend pool of a standard load balancer, with or without outbound rules.
In this section, you create a SQL server in Azure.
In the search box at the top of the portal, enter SQL. Select SQL databases in the search results.
In SQL databases, select + Create.
In the Basics tab of Create SQL Database, enter, or select the following information:
Setting
Value
Project details
Subscription
Select your subscription.
Resource group
Select test-rg.
Database details
Database name
Enter sql-db.
Server
Select Create new. Enter sql-server-1 in Server name (Server names must be unique, replace sql-server-1 with a unique value). Select (US) East US 2 in Location. Select Use SQL authentication. Enter a server admin sign-in and password. Select OK.
Want to use SQL elastic pool?
Select No.
Workload environment
Leave the default of Production.
Backup storage redundancy
Backup storage redundancy
Select Locally redundant backup storage.
Select Next: Networking.
In the Networking tab of Create SQL Database, enter, or select the following information:
Setting
Value
Network connectivity
Connectivity method
Select Private endpoint.
Private endpoints
Select +Add private endpoint.
Create private endpoint
Subscription
Select your subscription.
Resource group
Select test-rg.
Location
Select East US 2.
Name
Enter private-endpoint-sql.
Target subresource
Select SqlServer.
Networking
Virtual network
Select vnet-1.
Subnet
Select subnet-1.
Private DNS integration
Integrate with private DNS zone
Select Yes.
Private DNS zone
Leave the default of privatelink.database.windows.net.
Select OK.
Select Review + create.
Select Create.
Oluline
When adding a Private endpoint connection, public routing to your Azure SQL server isn't blocked by default. The setting "Deny public network access" under the "Firewall and virtual networks" blade is left unchecked by default. To disable public network access, ensure this is checked.
Disable public access to Azure SQL logical server
For this scenario, assume you would like to disable all public access to your Azure SQL server, and only allow connections from your virtual network.
In the search box at the top of the portal, enter SQL server. Select SQL servers in the search results.
Select sql-server-1.
in Security, select Networking tab, then select Disable for Public network access.
Select Save.
Test connectivity to private endpoint
In this section, you use the virtual machine you created in the previous steps to connect to the SQL server across the private endpoint.
In the search box at the top of the portal, enter Virtual machine. Select Virtual machines in the search results.
Select vm-1.
In Operations select Bastion.
Enter the username and password for the virtual machine.
Select Connect.
To verify name resolution of the private endpoint, enter the following command in the terminal window:
Bash
nslookup server-name.database.windows.net
You receive a message similar to the following example. The IP address returned is the private IP address of the private endpoint.
A SQL command prompt is displayed on successful sign in. Enter exit to exit the sqlcmd tool.
When you finish using the resources that you created, you can delete the resource group and all its resources.
In the Azure portal, search for and select Resource groups.
On the Resource groups page, select the test-rg resource group.
On the test-rg page, select Delete resource group.
Enter test-rg in Enter resource group name to confirm deletion, and then select Delete.
Next steps
In this tutorial, you learned how to create:
Virtual network and bastion host.
Virtual machine.
Azure SQL server with private endpoint.
You used the virtual machine to test connectivity privately and securely to the SQL server across the private endpoint.
As a next step, review the Web app with private connectivity to Azure SQL Database architecture scenario, which connects a web application outside of the virtual network to the private endpoint of a database.
Learn how to securely connect an Azure SQL server using an Azure Private Endpoint via the Azure portal, ensuring private and safe communication with your SQL server.
Administer an SQL Server database infrastructure for cloud, on-premises and hybrid relational databases using the Microsoft PaaS relational database offerings.
Mark a subnet as a virtual network service endpoint. Then add the endpoint as a virtual network rule to the ACL for your database. Your database then accepts communication from all virtual machines and other nodes on the subnet.
In the first part of this two-part video segment, Rohit Nayak explains what Private Endpoint for Azure SQL Database is and how it relates to the overall connectivity story for Azure SQL. Additional Resources:Private Link in Azure SQL DatabasePrivate Link for AzureEven more videos on the topic[00:46] Connectivity architecture for public endpoint[01:46] Private Link overview[03:55] Why Private Link?[05:08] How does Private Endpoint work?[06:55] Client connectivity scenarios to Private Endpoint[09:05