Quickly load balance IPv6 services with NLB
Network Load Balancer (NLB) can forward IPv6 network requests. This topic describes how to enable IPv6 attachment for a dual-stack NLB instance. After this feature is enabled, the NLB instance can use both IPv4 and IPv6 Elastic Compute Service (ECS) instances as backend servers. This allows clients on IPv6 networks to access IPv4 and IPv6 services that are deployed on the backend servers through the NLB instance.
Scenario
This topic shows how to use an NLB instance to forward requests from IPv6 clients, allowing them to access both IPv4 and IPv6 services within a Virtual Private Cloud (VPC) over the Internet. You will create ECS instances with both IPv4 and IPv6 addresses, a dual-stack NLB instance in the VPC, and a server group with IPv6 attachment enabled. The NLB instance will then route requests from IPv6 clients to the IPv4 and IPv6 services deployed on the backend ECS instances.
Limits
For a list of regions that support dual-stack NLB instances, see Regions that support dual-stack NLB.
To use the dual-stack feature, you must enable IPv6 for the vSwitches in your VPC's zones.
A dual-stack NLB instance can forward traffic from IPv6 clients to both IPv4 and IPv6 backend services.
You cannot upgrade an existing IPv4 instance to a dual-stack instance. You must create a new dual-stack instance.
When you create a listener for an IPv4 NLB instance, you cannot add a server group with IPv6 attachment enabled.
Prerequisites
You have created a VPC named VPC1 in the China (Shanghai) region, and you have enabled an IPv6 CIDR block for the VPC, which automatically creates an IPv6 gateway.
You have created a vSwitch named vSwitch1 in Zone E and a vSwitch named vSwitch2 in Zone G in the China (Shanghai) region. You have enabled IPv6 for both vSwitches.
To ensure that your NLB instance can scale as needed, reserve at least eight IP addresses in each vSwitch where the NLB instance is deployed.
You have registered a domain name and completed the ICP filing.
Step 1: Create and configure ECS instances
Log on to the VPC console.
In the navigation pane on the left, click vSwitch.
Select the region where the vSwitch resides. This topic uses China (Shanghai) as an example.
On the vSwitch page, find the target vSwitch and choose in the Actions column.
On the Elastic Compute Service page, on the Custom Launch tab, create two ECS instances. Name the IPv4 instance ECS01 and the IPv6 instance ECS02. Ensure that the security groups associated with the ECS instances allow traffic on port 80. For more information, see Create an instance by using the wizard.
Remotely connect to the ECS01 and ECS02 instances. For more information, see Connection methods.
On ECS01, run the following commands to deploy an Nginx service.
yum install -y nginx systemctl start nginx.service cd /usr/share/nginx/html/ echo "Hello World ! this is ipv4 rs." > index.htmlOn ECS02, run the following commands to deploy an Nginx service.
yum install -y nginx systemctl start nginx.service cd /usr/share/nginx/html/ echo "Hello World ! this is ipv6 rs." > index.htmlConfigure an IPv6 address for the ECS02 instance. For more information, see IPv6 communication.
NoteYou can skip this step if your ECS02 instance uses the Alibaba Cloud Linux 3.2104 LTS 64-bit image and you selected Assign IPv6 Address Free of Charge for the IPv6 parameter in the Network and Security Group section during instance creation.
Remotely connect to the ECS02 instance in the VPC.
Configure the IPv6 address.
Run the
ip addr | grep inet6orifconfig | grep inet6command.If output similar to the following is returned, an IPv6 address is already configured and you can skip the rest of this step.
[root@iZbpxxx fxe4Z ~]# ip addr | grep inet6 inet6 ::1/128 scope host inet6 2408:4005:xxx:xxx:7cd5:aa9c/128 scope global dynamic noprefixroute inet6 fe80::xxx:cc1c/64 scope link noprefixrouteIf the command does not return any output that contains inet6, the IPv6 service is not enabled on the instance. You must first enable the IPv6 service.
If inet6 output is returned, the IPv6 service is enabled on the ECS02 instance and an IPv6 address is recognized. You can proceed to configure the IPv6 address.
Step 2: Configure an IPv6 security group rule
You must configure an IPv6 security group rule for the ECS02 instance to allow inbound requests from IPv6 clients.
Log on to the ECS console.
In the left-side navigation pane, choose .
In the top navigation bar, select the region of the security group. This topic uses China (Shanghai).
On the Security Groups page, find the target security group and click Manage Rules in the Operation column.
On the Security Group Details page, click the Inbound tab in the Rules section, and then click Add Rule.
On the Create Security Group Rule page, configure an IPv6 security group rule with the following parameters and click Submit.
Parameter
Description
Action
Specifies whether to allow or deny traffic. In this topic, select Allow.
Priority
The priority of the security group rule. A smaller value indicates a higher priority. Valid values: 1 to 100.
In this topic, the default value 1 is used.
Protocol
The protocol type of the traffic. In this topic, select All ICMPv6.
Source
Select IPv6 as the type and enter ::/0 to allow access from all IPv6 addresses.
NoteThe source configured in this topic is for demonstration purposes only. You can allow access from specific IPv6 CIDR blocks based on your business requirements.
Destination (this instance)
The destination IP address and port for the traffic.
If you set Protocol to All ICMPv6, this parameter defaults to All (-1/-1) and cannot be changed.
Step 3: Create an NLB instance
Log on to the NLB console.
On the Instances page, click Create NLB.
On the buy page, configure the following parameters, then click Buy Now and follow the prompts to create the instance.
This topic describes only the parameters that are relevant to this scenario. Use the default values for other parameters. For more information, see Create and manage an NLB instance.
By default, a new public dual-stack NLB instance receives a private IPv6 address. To change it to a public address, follow these steps:
Return to the Instances page, find the target NLB instance, and click its ID.
On the Instance Details tab, find Network in the Basic Information section. Then, click Change Network Type to the right of Private IPv6.
In the Change Network Type dialog box, click OK.
After the change is complete, the network type for IPv6 is changed from private to public.
Step 4: Create a server group
-
In the top navigation bar, select the region in which the NLB instance is deployed.
On the Server Groups page, click Create Server Group.
In the Create Server Group dialog box, configure the following parameters and click Create.
This section describes only the key parameters. Use the default values for other parameters. For more information, see Create a server group.
Parameter
Description
Server Group Type
The type of backend server to add to the server group. In this topic, select Server.
Server Group Name
Enter a custom name for the server group.
VPC
The VPC to which the server group belongs.
NoteMake sure that IPv6 is enabled for the selected VPC and that it is the same VPC selected when you created the NLB instance.
Backend Server Protocol
Select a backend protocol. In this topic, select TCP.
Scheduling Algorithm
Select a scheduling algorithm. In this topic, select Weighted Round-Robin.
IPv6
Specifies whether to enable IPv6 attachment. In this topic, you must enable IPv6.
Health Check
Enables or disables health checks. Use the default settings in this topic.
In the Actions column of the server group, click Modify Backend Server, and then click Add Backend Server.
In the Add Backend Server panel, set Server to ECS/ENI, select the ECS01 and ECS02 instances that you created, and in the IP column, select the IPv4 address for ECS01 and the IPv6 address for ECS02. Then, click Next.
On the Ports/Weights page, set the weights and ports for the ECS01 and ECS02 instances, and then click OK.
In this topic, the port for the ECS instances is set to 80 and the weight is set to the default value of 100.
Step 5: Configure a listener
-
In the left-side navigation pane, choose .
On the Instances page, find the target instance and click Create Listener in the Actions column.
On the Configure Listener page, configure the following parameters and click Next.
This topic describes only the parameters that are relevant to this scenario. Use the default values for other parameters. For more information about how to configure a listener, see Add a TCP listener.
Parameter
Description
Select Listener Protocol
The protocol for the listener. In this topic, select TCP.
Listener Port
The listener port used to receive requests and forward 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.
In the Server Group configuration wizard, select the Server Type and the target server group under Server Type, view the backend server information, and then click Next.
On the Confirm page, confirm the configuration details and click Submit.
Click OK to return to the Listener tab. When the Health Check Status of the listener changes to Healthy, it indicates that the backend servers ECS01 and ECS02 can process requests forwarded by the NLB instance.
Step 6: Configure DNS resolution
Use CNAME records to map your custom domain name to the NLB instance domain name.
-
In the left-side navigation pane, choose .
On the Instances page, copy the domain name of the NLB instance that you want to manage.
Perform the following steps to create a CNAME record:
NoteIf 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.
Log on to the DNS console.
On the Authoritative DNS Resolution page, find your domain name and click DNS Settings in the Actions column.
On the DNS Settings tab of the domain name details page, click Add DNS Record.
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.
NoteIf 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 7: Verify the result
Test the NLB instance availability:
NoteMake sure that your client supports IPv6 before you begin testing.
Use any Linux client that can access IPv6 services. If telnet is not installed on a CentOS system, run the
yum install -y telnetcommand to install it.Run the
telnet <domain_name> <port>command. If a response containing Connected to nlb-... is returned, this confirms that the NLB instance is forwarding requests to the backend server.Trying *.*.*.*... Connected to www.example.com. Escape character is '^]'Visit
http://<domain_name>in a browser. If the following content is displayed, it indicates that the NLB instance can forward requests to the backend servers.The page displays the text
Hello World ! this is ipv6 rs..
(Optional) Simulate a failure:
On ECS01, run the
systemctl stop nginx.servicecommand to stop the application.Wait a few minutes, then run the
telnet <domain_name> <port>command again from the client. A response message that contains Connected to nlb-... is still returned.Trying *.*.*.*... Connected to www.example.com. Escape character is '^]'Visit
http://<domain_name>in a browser. If the following content is displayed, it indicates that the NLB instance is still forwarding requests to a healthy backend server.The page displays the text
Hello World ! this is ipv6 rs., which indicates that the verification is successful.On ECS01, run the
systemctl start nginx.servicecommand to restart the application. On ECS02, run thesystemctl stop nginx.servicecommand to stop the application.Wait a few minutes, then run the
telnet <domain_name> <port>command again from the client. A response message that contains Connected to nlb-... is still returned.Trying *.*.*.*... Connected to www.example.com. Escape character is '^]'Visit
http://<domain_name>in a browser. If the following content is displayed, it indicates that the NLB instance is forwarding requests to a healthy backend server.The response text
Hello World ! this is ipv4 rs.is returned, which indicates that the request was successfully forwarded to the IPv4 backend server.The failure of a single backend server does not affect the availability of the NLB instance.
Release resources
Clean up the ECS, security group, and other resources:
Delete the ECS01 instance and its security group:
Log on to the ECS console. In the top navigation bar, select the region where the instance is deployed. Find the ECS01 instance, click the
icon in the Actions column, choose Release, select immediate release, and then confirm the operation.Log on to the ECS console. In the top navigation bar, select the region where the instance is deployed. Select the custom security group that is associated with ECS01 and click Delete to delete the security group.
Follow the preceding steps to delete the ECS02 instance and its security group resources.
Delete the DNS record.
For more information, see Delete a DNS record.
Clean up the NLB resources:
Log on to the NLB console. In the top navigation bar, select the region where the instance is deployed. Click the
icon in the Actions column of the instance, choose Release, and then confirm the operation.Log on to the NLB console. In the top navigation bar, select the region where the instance is deployed. On the Server Groups page, click the
icon in the Actions column of the server group, choose Delete, and then confirm the operation.
Clean up the VPC resources:
Log on to the VPC console. In the top navigation bar, select the region where the instance is deployed.
Click Delete in the Actions column of the instance. In the dialog box that appears, select the option for a forced deletion to delete the VPC and vSwitch resources.
Related documents
For more information about NLB, such as its use cases and components, see What is NLB?.
For more information about the features of NLB, see Features.
For more information about NLB quotas and how to increase them, see Limits.
For more information about the regions that support NLB, see NLB regions and zones.
For more information about how NLB is billed, see Billing.