All Products
Search
Document Center

Server Load Balancer:Get started with NLB for IPv4 load balancing

Last Updated:Jun 04, 2026

Alibaba Cloud Network Load Balancer (NLB) supports TCP, UDP, and SSL over TCP, and provides Layer 4 load balancing capabilities. Create an NLB instance with a server group, listener, and DNS record to distribute client requests across backend IPv4 servers.

Prerequisites

  • A VPC (VPC1) is created in the China (Shanghai) region with a vSwitch in Zone E (VSW1) and Zone G (VSW2). Create a VPC and a vSwitch.

    Reserve at least eight IP addresses in each vSwitch for the NLB instance to scale properly.
  • Two Elastic Compute Service (ECS) instances are deployed: ECS01 in VSW1 and ECS02 in VSW2.

    • Create an instance by using the wizard.

    • The following commands show how to deploy applications on ECS01 and ECS02:

      Commands for deploying an application on ECS01

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

      Commands for deploying an application on ECS02

      yum install -y nginx
      systemctl start nginx.service
      cd /usr/share/nginx/html/
      echo "Hello World ! this is ECS02." > index.html
  • A domain name is registered with an ICP number. Register a domain name on Alibaba Cloud. Overview.

Example VPC1 configurations:

Click to view VPC configurations

Parameter

Description

Name

VPC1

Region

China (Shanghai)

IPv4 CIDR

192.168.0.0/16

vSwitch

Name: VSW1

Zone: Zone E

IPv4 CIDR: 192.168.5.0/24

Name: VSW2

Zone: Zone G

IPv4 CIDR: 192.168.6.0/24

Example ECS configurations:

Click to view ECS instance configurations

ECS instance

Region

VPC

Zone and vSwitch

ECS configuration

ECS01

China (Shanghai)

VPC1

Zone E | VSW1

Image: Alibaba Cloud Linux 3.2104 LTS 64-bit

ECS02

Zone G | VSW2

Step 1: Create an NLB instance

  1. Log on to the NLB console.

  2. In the top navigation bar, select the region in which the NLB instance is deployed.

  3. On the Instances page, click Create NLB.

  4. On the Network Load Balancer (Pay-As-You-Go) page, configure the parameters. Click Buy Now.

    Only key parameters are listed. Use defaults for other parameters. For more information, see Create and manage NLB instances.

    Parameter

    Description

    Region

    Select the region for the NLB instance.

    Network Type

    Select a network type. The system assigns public or private IP addresses based on the selected type. Internet-facing is selected in this example.

    VPC

    Select the VPC for the NLB instance.

    Zone

    Select at least two zones. In this example, Shanghai Zone E and Shanghai Zone G are selected, and a vSwitch in each zone is selected.

    IP Version

    Select an IP version. In this example, IPv4 is selected.

    Instance Name

    Enter a name for the NLB instance.

    Resource Group

    Select a resource group for the NLB instance.

    Service-linked Role

    When you first create an NLB instance, click Create Service-linked Role to create AliyunServiceRoleForNlb. This role uses the AliyunServiceRolePolicyForNlb policy to grant NLB access to other cloud services. For more information, see System policies for NLB.

Step 2: Create a server group

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

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

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

    Only key parameters are listed. Use defaults for other parameters. Create and manage a server group.

    Parameter

    Description

    Server Group Type

    Select a server group type. In this example, Server Type is selected.

    Server Group Name

    Enter a name for the server group.

    VPC

    Select a VPC. Only servers in this VPC can be added to the server group.

    Backend Server Protocol

    Select a backend protocol. Valid values: TCP, UDP, SSL over TCP. In this example, TCP is selected.

    Scheduling Algorithm

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

    Health Check

    Health checks are enabled by default. In this example, the default setting is used.

  4. Click the ID of the server group to go to the Backend Servers tab.

  5. Click Add Backend Server . In the Add Backend Server panel, select ECS01 and ECS02 and click Next.

  6. In the Ports/Weights step, specify port 80, use the default weight 100, and then click OK.

Step 3: Configure a listener

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

  2. On the Instances page, find the NLB instance that you want to manage and click Create Listener.

  3. On the NLB Configuration Wizard page, configure the parameters and click Next.

    Only key parameters are listed. Use defaults for other parameters. For more information, see Add a TCP listener.

    Parameter

    Description

    Select Listener Protocol

    Select a listener protocol. In this example, TCP is selected.

    Listener Port

    Specify the listener port for receiving and forwarding requests. Port 80 is used in this example.

    Listener Name

    Enter a name for the listener.

    Advanced Settings

    Defaults are used in this example. Click Modify to customize.

  4. In the Server Group step, select a Server Type and select a server group from the drop-down list next to Server Type, view the backend servers, and then click Next.

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

  6. Click OK to return to the Listener tab. After the status of the listener in the Health Check Status changes to Healthy, ECS01 and ECS02 can forward requests from the NLB instance.

Step 4: Create a DNS record

Use CNAME records to map your custom domain name to the NLB instance domain name.

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

  2. On the Instances page, copy the domain name of the NLB instance that you want to manage.

  3. Perform the following steps to create a CNAME record:

    Note

    If your domain name is not registered through Alibaba Cloud Domains, add it to Alibaba Cloud DNS first. For more information, see Manage domain names. Skip this step for domains registered through Alibaba Cloud Domains.

    1. Log on to the Alibaba Cloud DNS console.

    2. On the Authoritative DNS Resolution page, find your domain name and click DNS Settings in the Actions column.

    3. On the DNS Settings tab of the domain name details page, click Add DNS Record.

    4. In the Add Record panel, configure the parameters and click OK. The following table describes the parameters.

      Parameter

      Description

      Record Type

      Select CNAME from the drop-down list.

      Hostname

      Domain name prefix. @ is used in this example.

      Note

      If the domain name is a root domain name, enter @.

      DNS Query Source

      Select Default.

      Record Value

      Enter the CNAME, which is the domain name of the NLB instance.

      TTL Period

      TTL value for DNS caching. The default is used in this example.

Step 5: Verify the results

  1. Test the availability of the NLB instance.

    1. This example uses a Linux client with Internet access. On CentOS, install telnet if needed: yum install -y telnet.

    2. Run telnet Domain name Port. A response containing Connected to nlb-... confirms the NLB instance is forwarding requests.

      Trying *.*.*.*...
      Connected to www.example.com.
      Escape character is '^]'.

      Open http://domain name in a browser. A response as shown below confirms the NLB instance is forwarding requests.

      image

  2. (Optional) Simulate faults.

    1. Stop the application on ECS01 by running systemctl stop nginx.service.

    2. Run telnet Domain name Port again. A response containing Connected to nlb-... confirms connectivity.

      Trying *.*.*.*...
      Connected to www.example.com.
      Escape character is '^]'.

      Open http://domain name in a browser. A response as shown below confirms the NLB instance is forwarding requests.

      image

    3. Restart the application on ECS01 and stop it on ECS02. Run systemctl start nginx.service on ECS01 and systemctl stop nginx.service on ECS02.

    4. Run telnet Domain name Port again. A response containing Connected to nlb-... confirms connectivity.

      Trying *.*.*.*...
      Connected to www.example.com.
      Escape character is '^]'.

      Open http://domain name in a browser. A response as shown below confirms the NLB instance is forwarding requests.

      image

    5. These tests confirm that a single server failure does not affect NLB instance availability.

Release resources

  1. Release the ECS instances and the security groups.

    1. Delete ECS01 and its security group.

      1. Go to the ECS console - Instance page. In the top navigation bar, select the region in which ECS01 instance resides, and click the image.png icon on the right side of ECS01. In the dialog box that appears, select Release to immediately release the instance.

      2. Go to the ECS console - Security Groups page. In the top navigation bar, select the region in which ECS01 resides, select the security group of ECS01, and then click Delete to delete the security group.

    2. Repeat the preceding steps to delete ECS02 and its security group.

  2. Delete the DNS record.

    For more information, see Delete a record.

  3. Release NLB resources.

    1. Go to the NLB console. In the top navigation bar, select the region where the NLB instance resides. Find the NLB instance, click the image.png icon in the Actions column, and click Release. In the message that appears, click Confirm.

    2. Go to the NLB console. In the top navigation bar, select the region in which the NLB instance resides. On the Server Group page, find the server group, click the image.png icon in the Actions column, and click Delete. In the message that appears, click OK.

  4. Release VPC resources.

    1. Go to the VPC console. In the top navigation bar, select the region where the VPC resides.

    2. Click Delete in the Actions column and select Forcefully Delete to delete the VPC and the vSwitches.

References