All Products
Search
Document Center

:Forward traffic to RDS Custom instances through NLB

Last Updated:Jun 20, 2026

You can use Alibaba Cloud Network Load Balancer (NLB) to efficiently route traffic to an RDS Custom instance, ensuring balanced traffic distribution. This solution also connects your RDS Custom instance to the internet, protecting your internal network while improving service availability and scalability.

Prerequisites

An application service must be deployed on the target RDS Custom instance. This topic uses an Nginx service as an example. Run the following commands on the target RDS Custom instance:

yum install -y nginx
systemctl start nginx.service
cd /usr/share/nginx/html/
echo "Hello World ! this is RDS Custom." > index.html

Step 1: Create an NLB instance

  1. Log on to the NLB console.

  2. In the top navigation bar, select the same region as your target RDS Custom instance.

  3. On the Instance page, click Create NLB.

  4. On the NLB (Pay-As-You-Go) purchase page, configure the following parameters, click Buy Now, and follow the on-screen prompts to create the instance.

    Only the relevant parameters are described below. Use the default values for other parameters. For details, see Create and manage NLB instances.

    Parameter

    Description

    Region

    Select the same region as your target RDS Custom instance.

    Network Type

    Select a network type for the instance. The system assigns a private or public service address based on your selection. In this topic, Private is selected.

    • Private: A private IP address is provided for each zone. The NLB instance can be accessed only over the Alibaba Cloud internal network, for example, from an ECS instance in the same VPC. The NLB instance cannot be accessed from the internet.

    • Public: A public IP address and a private IP address are provided for each zone. An Internet-facing NLB instance uses an elastic IP address (EIP) to provide public services. If you select this option, you are charged for the EIP instance, and for bandwidth or data transfer.

    VPC

    Select the same VPC as your target RDS Custom instance.

    Zone

    Select at least two zones. For example, if your RDS Custom instance is in the China (Shanghai) region, you can select China (Shanghai) Zone E and a vSwitch in that zone, and China (Shanghai) Zone L and a vSwitch in that zone.

    Protocol Version

    Select an IP version for the instance. In this topic, IPv4 is selected.

    Service-linked Role

    If you are creating an NLB instance for the first time, click Create Service-linked Role to create a service-linked role named AliyunServiceRoleForNlb. The system grants this role the AliyunServiceRolePolicyForNlb policy, which allows NLB to access other cloud resources. For more information, see System policies for Network Load Balancer.

    Instance Name

    Enter a custom name for the instance.

    Resource Group

    Select a resource group to which the instance belongs.

Step 2: Create an NLB server group

  1. In the left-side navigation pane, choose NLB > Server Group.

  2. On the Server Group page, click Create Server Group.

  3. In the Create Server Group dialog box, configure the following parameters and click Create.

    The following table describes only the key parameters. Use the default values for other parameters. For details, see Create a server group.

    Parameter

    Description

    Server Group Type

    The type of backend server to add to the server group. In this topic, IP Type is selected.

    Server Group Name

    Enter a name for the server group.

    VPC

    Select the same VPC as your target RDS Custom instance.

    Backend Server Protocol

    Select a backend protocol. In this topic, TCP is selected.

    Scheduling Algorithm

    Select a scheduling algorithm. In this topic, Weighted Round-robin is selected.

    Health Check

    Enable health checks and use the default settings.

  4. After the server group is created, click its ID, and then click the Backend Servers tab.

  5. Click Add IP Address. In the Add Backend Server panel, enter the private IP address of your RDS Custom instance, and then click Next.

  6. In the Configure Ports and Weights step, set the port to 80 and keep the default weight of 100. Then, click OK.

    Note

    If any-port forwarding is enabled for the server group, you do not need to specify a port when you add a backend server. NLB forwards traffic to backend servers based on the frontend request port.

Step 3: Configure a listener

  1. In the left-side navigation pane, choose NLB > Instances.

  2. On the Instance page, find the target instance and click Create Listener in the Actions column.

  3. In the Configure Server Load Balancer wizard, configure the following parameters and click Next.

    Only the relevant parameters are described below. Use the default values for other parameters. For details about how to configure a listener, see Add a TCP listener.

    Parameter

    Description

    Select Listener Protocol

    Select a protocol for the listener. In this topic, TCP is selected.

    Listener Port

    The port that receives requests and forwards them to backend servers. In this topic, enter 80.

    Listener Name

    Enter a custom name for the listener.

    Advanced Settings

    Use the default settings. You can click Modify to change them.

  4. In the Server Group step, select IP Type as the server group type and then select the target server group. Review the added backend server information, and then click Next.

  5. In the Confirm step, confirm the configurations and click Submit.

  6. Click OK. On the Listener tab, check the Health Check Status column for the listener. If the status is Normal, the backend RDS Custom instance can process requests forwarded by the NLB instance.

Step 4: Verify the result

  1. On the NLB instance details page, obtain the Domain Name of the instance.

    You can create a CNAME record to map a custom domain name to the DNS name of the NLB instance. For more information, see Add a DNS record.

  2. On an ECS instance in the same region and VPC as your RDS Custom instance, run the following telnet command to verify the routing. This example uses an ECS instance that runs CentOS 7.

    Note

    If telnet is not installed, run the yum install -y telnet command to install it.

    telnet <target_address> <listener_port>
    • target_address: The DNS name of the NLB instance or the private IP address of the RDS Custom instance. This topic uses the DNS name of the NLB instance as an example.

    • listener_port: The listener port that you configured for the NLB instance. This topic uses 80 as an example.

    Example:

    telnet nlb-r3rw8kyfwm5bfm****.cn-shanghai.nlb.aliyuncsslb.com 80

    If you receive the following response, the NLB instance can forward requests to the backend server.

    Trying 47.116.XXX.XXX...
    Connected to nlb-r3rw8kyfwm5bfm****.cn-shanghai.nlb.aliyuncsslb.com.
    Escape character is '^]'.
  3. Run the curl command to access the default webpage of the Nginx service on the RDS Custom instance.

    curl http://nlb-r3rw8kyfwm5bfm****.cn-shanghai.nlb.aliyuncsslb.com

    The following response is returned:

    Hello World ! this is RDS Custom.

(Optional) Route internet traffic to RDS Custom

  1. Log on to the Network Load Balancer console.

  2. In the top navigation bar, select the instance's region.

  3. On the Instance page, find the target internal-facing NLB instance and click its ID.

  4. On the Instance Details tab, go to the Basic Information section. Find Network Type and click Change Network Type next to IPv4.

  5. In the Change Network Type dialog box, select EIP for IP Type.

  6. From the Associate EIP drop-down list for each zone, select Purchase EIP or an existing EIP. Then, click Confirm change.

    Note

    You must allocate an EIP for each zone in the list.

    If you select Purchase EIP, the new EIP is released when you release the NLB instance or change its network type from Internet-facing to internal-facing. If you select an existing EIP, the EIP is retained in these scenarios.

    You can view information about your EIPs in the Elastic IP Addresses console.

  7. On the Instance Details tab, check the Network Type.

    The change takes about one minute to take effect. The operation is successful when the Network Type for IPv4 on the Instance Details tab changes to Public.

  8. Verify the result.

    In a web browser, go to http://nlb-r3rw8kyfwm5bfm****.cn-shanghai.nlb.aliyuncsslb.com. The page loads and displays Hello World ! this is RDS Custom..

Related topics