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:
Editions: Cluster Edition, High-availability Edition. Basic Edition is not supported.
Instance types: General-purpose and Dedicated. Shared instance types are not supported.
Billing methods: 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
Newly created VPN gateways support only IPsec-VPN connections in dual-tunnel mode. If you have an existing single-tunnel VPN gateway, upgrade its IPsec-VPN connections to dual-tunnel mode to ensure high availability and benefit from the latest features.
Console
To create a VPN gateway using the console, go to the VPN Gateway buy page and configure the following parameters:
Region: Select the same region as your VPC.
Gateway Type: Select Standard to ensure the gateway uses industry-standard commercial cryptographic algorithms for IPsec-VPN connections.
Network Type: Select Public to assign a public IP address for the IPsec-VPN connection. For private connectivity, use a private IPsec-VPN connection and bind it to a transit router.
Tunnels: Select Dual-tunnel to enhance availability.
Select the associated VPC and two vSwitches in different availability zones. When IPsec-VPN is enabled, the system creates an Elastic Network Interface (ENI) in each vSwitch. These ENIs serve as the traffic interfaces between the IPsec-VPN connection and the VPC, and each ENI consumes one IP address.
In regions that support only a single availability zone, zone-level disaster recovery is not possible. To maintain high availability for the IPsec-VPN connection, select two different vSwitches within the same zone.
The associated vSwitches cannot be modified after the VPN gateway is created.
Maximum Bandwidth: The maximum supported bandwidth varies by region. If you select 10 Mbit/s or 5 Mbit/s, the inbound peak bandwidth from the on-premises data center to the VPN gateway is limited to 10 Mbit/s.
Enable IPsec-VPN and disable SSL-VPN.
If IPsec-VPN is not enabled during creation, you can enable it later by locating the VPN gateway in the console and clicking Enable in the Feature Configuration column.
API
To create a VPN gateway using the API, call the CreateVpnGateway operation and specify the required parameters.
1.2. Create an SSL server
Log on to the VPN Gateway console.
In the left-side navigation pane, choose .
In the top navigation bar, select the region of the SSL server.
The SSL server and VPN gateway must reside in the same region.
On the SSL Servers page, click Create SSL Server.
In the Create SSL Server panel, set the following parameters and click OK.
Parameter
Description
Name
Enter a name for the SSL server.
Resource Group
The resource group to which the VPN gateway belongs.
The SSL server is automatically added to the same resource group as the VPN gateway.
VPN Gateway
Select the VPN gateway to associate with the SSL server.
Make sure that SSL-VPN is enabled for the VPN gateway.
Local Network
The CIDR block that clients use to access resources through the SSL-VPN connection.
The CIDR block can be the CIDR block of a virtual private cloud (VPC), a vSwitch, a cloud service such as Object Storage Service (OSS) or ApsaraDB RDS, or a data center that is connected to a VPC over an Express Connect circuit.
You can click Add Local Network to add up to five local CIDR blocks. The following CIDR blocks cannot be used for a local network:
127.0.0.0~127.255.255.255
169.254.0.0~169.254.255.255
224.0.0.0~239.255.255.255
255.0.0.0~255.255.255.255
NoteThe prefix length of the local network's subnet mask must be between 8 and 32 bits.
Client CIDR Block
The IP address pool from which the VPN gateway assigns addresses to client virtual network interfaces. This is not the client's existing private network. When a client connects, the VPN gateway assigns it an IP address from this block. The client then uses this IP address to access cloud resources.
Make sure that the number of IP addresses in the client CIDR block is at least four times the maximum number of SSL-VPN connections supported by the VPN gateway.
ImportantThe subnet mask of the Client CIDR Block must have a prefix length between 16 and 29 bits.
The client CIDR block must not overlap with the local CIDR block, the VPC CIDR block, or route CIDR blocks associated with the client.
We recommend that you use 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, or their subnets for the client CIDR block. If you must use a public IP address range, you must configure it as a user-defined CIDR block for the VPC to ensure proper routing. For more information, see VPC FAQ.
After you create the SSL server, the system automatically adds a route for the Client CIDR Block to the route table of the VPC. Do not manually add this route to the VPC route table. Otherwise, SSL-VPN connections may be disrupted.
Advanced Configuration
Protocol
The protocol used by the SSL-VPN connection. Default value: TCP(Recommended). Valid values:
UDP
TCP(Recommended)
Port
The port that is used by the SSL server. Valid values are in the range of 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 that is used by an SSL-VPN connection.
If the client uses Tunnelblick or OpenVPN V2.4.0 or later, the SSL server dynamically negotiates with the client about the encryption algorithm and uses the most secure encryption algorithm that is supported by the SSL server and the client. The encryption algorithm that you specify for the SSL server does not take effect.
If the client uses OpenVPN of a version that is earlier than 2.4.0, the SSL server and the client use the encryption algorithm that you specify for the SSL server. You can specify one of the following encryption algorithms for the SSL server:
AES-128-CBC
AES-192-CBC
AES-256-CBC
none
A value of none indicates that no encryption algorithm is used.
Compressed
Specifies whether to compress the data that is transmitted over the SSL-VPN connection. Default value: No. Valid values:
Yes
No (default)
Two-factor Authentication
Specifies whether to enable two-factor authentication for the VPN gateway. By default, two-factor authentication is disabled.
Two-factor authentication verifies the identity of a client by using the default SSL client certificate and the username and password of IDaaS EIAM before an SSL-VPN connection is established. The client must pass both authentications before the connection can be created. Two-factor authentication helps prevent user identity theft and unauthorized SSL-VPN connections. It efficiently improves the security of SSL-VPN connections and protects sensitive data in VPCs against data breaches. For more information, see SSL-VPN two-factor authentication.
After two-factor authentication is enabled, you can select the IDaaS EIAM instance and IDaaS application ID used for authentication.
NoteIf you use the two-factor authentication feature for the first time, you must first authorize VPN to access cloud resources.
When you create an SSL server in the UAE (Dubai) region, we recommend that you associate the SSL server with an IDaaS EIAM 2.0 instance in Singapore to reduce latency.
You can no longer purchase IDaaS EIAM 1.0 instances. If your Alibaba Cloud account has an IDaaS EIAM 1.0 instance, you can still specify the IDaaS EIAM 1.0 instance after you enable the two-factor authentication feature.
If your Alibaba Cloud account has no IDaaS EIAM 1.0 instance, you can specify only an IDaaS EIAM 2.0 instance after you enable the two-factor authentication feature.
You may need to update the VPN gateway to associate it with an IDaaS EIAM 2.0 instance. For more information, see Announcement on the change of supporting IDaaS EIAM 2.0 instances for two-factor authentication of SSL-VPN connections.
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.
-
In the Create SSL Client panel, configure the SSL client certificate and click OK.
Configuration
Description
Name
Enter a name for the SSL client certificate.
Resource Group
Select the resource group to which the SSL server belongs.
The SSL client certificate must be in 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.NoteMake 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;