Access a self-managed on-premises SQL Server through a Linked Server
ApsaraDB RDS for SQL Server supports the linked server feature, which allows you to create linked servers between ApsaraDB RDS for SQL Server instances. If a network connection is available, you can also create a linked server to connect to a self-managed SQL Server instance. This feature enables cross-region data access, data consolidation and analysis, and data migration and synchronization. This topic describes how to create a linked server on an ApsaraDB RDS for SQL Server instance over a VPN to connect to a self-managed SQL Server instance.
Prerequisites
-
Your ApsaraDB RDS for SQL Server instance must meet the following requirements:
-
Instance edition: Cluster Edition and High-availability Edition. Basic Edition is not supported.
-
Instance type: general-purpose and dedicated. shared instances are not supported.
-
Billing method: subscription and pay-as-you-go. serverless instances are not supported.
-
-
Before you deploy a VPN Gateway, plan your network:
-
Ensure that the CIDR block of your on-premises client does not overlap with the CIDR block of the Virtual Private Cloud (VPC) that you need to access. Otherwise, communication fails.
-
Ensure that the client has internet connectivity.
-
Billing
Deploying a VPN Gateway incurs fees.
Step 1: Connect your VPC to the on-premises network
1.1. Create a VPN gateway instance
Create a VPN gateway
VPN Gateways are available in two forms: Enhanced and Standard. For details about their differences, see Enhanced vs. standard VPN.
Enhanced VPN gateway (console)
Only the following regions currently support Enhanced VPN Gateway: China (Beijing), China (Hangzhou), China (Shanghai), China (Shenzhen), China (Chengdu), China (Hong Kong), Singapore, Malaysia (Kuala Lumpur), Indonesia (Jakarta), US (Silicon Valley), US (Virginia), Germany (Frankfurt), UK (London).
Go to the Console VPN Gateway page, switch to the Enhanced IPsec-VPN tab, and click Create Enhanced IPsec-VPN to start configuration:
Region: Select the region where the VPC to be connected is located.
VPC: Select the target VPC.
vSwitch 1 and vSwitch 2: You need to select the associated VPC and 2 vSwitches deployed in different zones to ensure cross-zone high availability. After IPsec-VPN is enabled, the system creates one Elastic Network Interface (ENI) under each of the 2 vSwitches as the interface for traffic exchange with the VPC using IPsec connections. Each ENI occupies 1 IP address under the vSwitch.
China (Wuhan) supports only a single zone and cannot achieve zone-level disaster recovery. We recommend that you specify 2 different vSwitches in the zone to achieve high availability of IPsec connections.
Standard VPN gateway (console)
Go to the Console VPN Gateway page, on the Standard VPN Gateway tab, click Create VPN Gateway to start configuration:
If there is no Standard VPN Gateway tab, click Create VPN Gateway directly.
Region and zone: Select the region where the VPC is located.
Gateway Type: Select Standard. After an IPsec connection is established, the international standard commercial cryptographic algorithm (standard cryptographic algorithm) will be used.
Network Type: Select Public network. A public IP will be allocated to establish an IPsec connection. To establish a private IPsec connection, we recommend Use a private IPsec connection to bind the Enterprise Transit Router.
Tunnel: Select Dual tunnel.
VPC and Virtual vSwitch: You need to select the associated VPC and 2 vSwitches deployed in different zones to ensure cross-zone high availability. After IPsec-VPN is enabled, the system creates one Elastic Network Interface (ENI) under each of the 2 vSwitches as the interface for traffic exchange with the VPC using IPsec connections. Each ENI occupies 1 IP address under the vSwitch. After a VPN Gateway is created, the associated vSwitches cannot be modified.
China (Wuhan) supports only a single zone and cannot achieve zone-level disaster recovery. We recommend that you specify 2 different vSwitches in the zone to achieve high availability of IPsec connections.
Maximum Bandwidth: The maximum bandwidth specification supported by a VPN Gateway varies by region. If you select a bandwidth specification of 5 Mbps or 10 Mbps, the peak bandwidth from the on-premises data center to the VPN Gateway is limited to 10 Mbps. For details, see Quotas and limitations.
Enable IPsec-VPN and disable SSL-VPN.
If the created VPN Gateway does not have IPsec-VPN enabled, in the Feature Configuration column of the target VPN Gateway, click Enable after IPsec Connections.
Enabling IPsec-VPN for an existing VPN Gateway requires you to pay the feature price difference for the remaining time of the current billing cycle.
Billing Cycle:
You can choose whether to enable auto-renewal:
Monthly subscription: The auto-renewal cycle is 1 month.
Annual subscription: The auto-renewal cycle is 1 year.
API
Call CreateEnhancedVpnGateway to create an Enhanced VPN Gateway.
ImportantThe enhanced VPN gateway was launched in February 2024 and is currently in an invitation-only preview. To use this feature, contact your Alibaba Cloud engineer for access. Supported regions: Malaysia (Kuala Lumpur), UK (London), China (Chengdu), US (Virginia), US (Silicon Valley), China (Hong Kong), and Singapore.
Call CreateVpnGateway to create a Standard VPN Gateway.
Next Steps
To enable communication between the cloud VPC and the on-premises IDC, after the VPN Gateway instance is created, you also need to:
Customer Gateway: Register the information of the on-premises gateway device (such as IP address and BGP AS number) to Alibaba Cloud.
Create an IPsec-VPN connection: Create an IPsec encrypted tunnel between the Alibaba Cloud VPN Gateway and the on-premises gateway device to ensure that the connection can be established properly.
1.2. Create an SSL server
Log on to the VPN Gateway console.
In the left-side navigation pane, choose Network Interconnection > VPN > SSL Servers.
In the top navigation bar, select the region where you want to create the SSL server.
The SSL server must be in the same region as the associated VPN Gateway instance.
On the SSL Servers page, click Create SSL Server.
In the Create SSL Server panel, configure the following parameters and click OK.
Parameter
Description
Name
Enter a name for the SSL server.
Resource Group
Select the resource group of the VPN Gateway instance.
The SSL server is added to the same resource group as the gateway.
The access scope of the SSL-VPN connection is determined by the local network (based on the VPC CIDR block) and is unrelated to the resource group. Resources within the same VPC can be accessed over SSL-VPN regardless of the resource group they belong to.
VPN Gateway
Select the VPN Gateway instance.
The selected instance must have SSL-VPN enabled.
Local Network
The CIDR blocks that clients can access through the SSL-VPN connection.
A local network can be the CIDR block of a VPC, a vSwitch, an on-premises data center connected to a VPC through Express Connect, or a cloud service such as Object Storage Service (OSS) or ApsaraDB RDS.
Click Add Local CIDR Block to add multiple CIDR blocks. You can add up to five local networks. The following IP address ranges are not supported:
127.0.0.0 to 127.255.255.255
169.254.0.0 to 169.254.255.255
224.0.0.0 to 239.255.255.255
255.0.0.0 to 255.255.255.255
NoteThe subnet mask of a local network must be 8 to 32 bits in length.
Client CIDR Block
The IP address pool from which the VPN Gateway assigns addresses to clients. Not the private CIDR block of the client.
The client CIDR block must provide at least four times the number of IP addresses as the maximum concurrent SSL connections supported by the VPN Gateway instance.
ImportantThe subnet mask of the client CIDR block must be 16 to 29 bits in length.
The client CIDR block must not overlap with the Local Network, the VPC CIDR block, or any CIDR blocks routed on the client.
Use private CIDR blocks such as 10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16, or their subnets. To use a public IP range, configure it as a user-defined CIDR block in the VPC for proper routing. VPC FAQ and VPC FAQ.
After you create the SSL server, the system adds a route for the client CIDR block to the VPC route table. Do not manually add this route, as it may disrupt SSL-VPN traffic. If a vSwitch is associated with a custom route table, the system does not automatically add the route for the client CIDR block to that custom route table. You must manually add a route entry whose destination CIDR block is the client CIDR block and whose next hop is the VPN gateway. Otherwise, hosts in the CIDR blocks associated with the custom route table cannot communicate with SSL-VPN clients.
Advanced Configuration
Protocol
The protocol for the SSL-VPN connection. Valid values:
UDP
TCP (default)
Port
The port used by the SSL server. Valid values: 1 to 65535. Default value: 1194.
NoteThe following ports are not supported: 22, 2222, 22222, 9000, 9001, 9002, 7505, 80, 443, 53, 68, 123, 4510, 4560, 500, and 4500.
Encryption Algorithm
The encryption algorithm for the SSL-VPN connection.
If the client runs Tunnelblick or OpenVPN 2.4.0 or later, the server and client dynamically negotiate the encryption algorithm, prioritizing the most secure mutually supported option. The algorithm specified here does not take effect.
If the client runs OpenVPN earlier than 2.4.0, the specified algorithm is used. Supported algorithms:
AES-128-CBC (default)
AES-192-CBC
AES-256-CBC
none
Disables encryption.
Compressed
Whether to compress SSL-VPN traffic. Valid values:
Yes
No (default)
Two-factor Authentication
Whether to enable two-factor authentication. Disabled by default.
Two-factor authentication requires clients to pass both SSL certificate verification and username/password authentication against an IDaaS EIAM instance. SSL-VPN two-factor authentication.
When enabled, select an IDaaS EIAM instance and application ID for authentication.
NoteFor first-time use, grant the required permissions through Authorization.
When creating an SSL server in the UAE (Dubai) region, bind an IDaaS EIAM 2.0 instance in the Singapore region to reduce cross-region latency.
IDaaS EIAM 1.0 instances are no longer available for purchase. If one exists in your account, you can still bind it after enabling two-factor authentication.
If no IDaaS EIAM 1.0 instance exists in your account, only IDaaS EIAM 2.0 instances can be bound.
Binding an IDaaS EIAM 2.0 instance may require a VPN Gateway upgrade. [Change Notice] SSL-VPN two-factor authentication supports IDaaS EIAM 2.0.
Custom Client DNS
Configure DNS settings for all clients centrally. Available in some regions only. Configure DNS settings for clients.
1.3. Create an SSL client certificate
Log on to the VPN Gateway console.
In the navigation pane on the left, choose .
- In the top navigation bar, select the region of the SSL client.
On the SSL Clients page, click Create SSL Client.
On the Create SSL Client panel, configure the SSL client certificate based on the following information, and then click OK.
Configuration
Description
Name
Enter a name for the SSL client certificate.
Resource Group
Select the resource group of the SSL server.
The SSL client certificate must belong to the same resource group as the SSL server.
SSL Server
Select the SSL server to associate with this certificate.
1.4. Download the SSL client certificate
Log on to the VPN Gateway console.
In the navigation pane on the left, choose .
- In the top navigation bar, select the region of the SSL client.
On the SSL Clients page, find the SSL client certificate that you want to download and click Download Certificate in the Actions column.
1.5. Configure the client
-
Download and install an OpenVPN client.
-
Decompress the downloaded certificate package and copy the files to the config folder in the OpenVPN installation directory.
-
Click Connect to initiate a connection.
1.6. Test the connection
-
Create an ECS instance in the same VPC.
-
In the OpenVPN client, run the
pingcommand to test the connectivity to the ECS instance.Note-
Make sure that the security group rules for the ECS instance allow remote client connections. Set the authorization object to the client CIDR block that you specified in the SSL server configuration. You must also specify the service port of the on-premises database you want to access. For more information, see Security group configuration examples.
-
If the connection fails, a firewall on the local host might be blocking it. You must configure the firewall to allow remote connections.
-
Step 2: Create a linked server
Using SSMS
-
Connect to an ApsaraDB RDS for SQL Server instance by using SQL Server Management Studio (SSMS).
-
In SSMS, run the following SQL command to create a linked server:
DECLARE @linked_server_name sysname = N'yangzhao_slb', -- The name of the linked server, used to identify the remote server. @data_source sysname = N'****.sqlserver.rds.aliyuncs.com,3888 ', -- The IP address and port of the self-managed SQL Server database. Format: <IP>,<Port>. Example: 10.1.10.1,1433. @user_name sysname = N'ay15', -- The username to connect to the self-managed SQL Server database. @password nvarchar(128) = N'******', -- The password for the specified username. -- Other options for the linked server, provided in XML format. @link_server_options xml = N' <rds_linked_server> <config option="data access">true</config> <config option="rpc">true</config> <config option="rpc out">true</config> </rds_linked_server>' ; -- Call the sp_rds_add_linked_server stored procedure to create the linked server. EXEC sp_rds_add_linked_server @linked_server_name, @data_source, @user_name, @password, @link_server_options; -
Run the following SQL command to view the list of configured linked servers:
SELECT * FROM [yangzhao_slb].master.sys.servers;
Using DMS
-
Connect to an ApsaraDB RDS for SQL Server instance by using DMS.
-
In DMS, run the following SQL command to create a linked server:
-- Call the sp_rds_add_linked_server stored procedure to create the linked server. EXEC sp_rds_add_linked_server @linked_server_name = N'yangzhao_slb', -- The name of the linked server, used to identify the remote server. @data_source = N'10.1.10.1,1433', -- The IP address and port of the self-managed SQL Server database. Format: <IP>,<Port>. Example: 10.1.10.1,1433. @user_name = N'ay15', -- The username to connect to the self-managed SQL Server database. @password = N'******', -- The password for the specified username. -- Other options for the linked server, provided in XML format. @link_server_options = N' <rds_linked_server> <config option="data access">true</config> <config option="rpc">true</config> <config option="rpc out">true</config> </rds_linked_server>' ; -
Run the following SQL command to view the list of configured linked servers:
SELECT * FROM [yangzhao_slb].master.sys.servers;