Dual-stack NLB instances support IP version affinity. When enabled, IPv4 requests are forwarded to IPv4 backend servers and IPv6 requests to IPv6 backend servers, routing traffic by protocol version and simplifying your network architecture.
Architecture
Scenario
During IPv4-to-IPv6 migration, both services often need to coexist. When a server group contains both IPv4 and IPv6 backend servers, NLB by default does not distinguish between the IP versions of client requests and forwards traffic based only on the scheduling algorithm, such as round-robin or least connections.
This can cause cross-protocol forwarding — for example, an IPv6 client request might reach an IPv4-only backend server, or vice versa. Such mismatches can cause the following issues:
-
The backend server cannot obtain the real client IP address, which affects source-based regional analysis and access control.
-
To obtain the source IP address, you must deploy an additional proxy layer, such as Nginx with Proxy Protocol enabled, which increases operational costs.
Solution
NLB server groups support IP version affinity for 4-to-4 and 6-to-6 forwarding.
Backend servers can directly obtain original client IP addresses without an additional proxy layer. If all backend servers for a specific protocol fail health checks, requests are forwarded on a best-effort basis to other servers within the same protocol group but are not routed across protocols.
Prerequisites
You have registered a custom domain name. This tutorial uses the China (Shanghai) region to deploy the NLB instance. Therefore, you must apply for an ICP filing for your domain name.
Procedure
Before you begin, make sure that you have created a VPC named VPC1 in the China (Shanghai) region, created vSwitches VSW1 and VSW2 in availability zones E and G respectively, and enabled IPv6 on the vSwitches.
1. Create ECS instances and deploy services
-
Create two ECS instances with the following configurations.
Parameter
Region
VPC
vSwitch
IP version
Image
ecs-ipv4
China (Shanghai)
VPC1VSW1IPv4
Alibaba Cloud Linux 3.2104 LTS 64-bit
ecs-ipv6
VSW2IPv6
When you purchase the ECS instance, in the Network and Security Groups section, select Assign IPv6 Address Free of Charge.
-
Remotely connect to
ecs-ipv4andecs-ipv6, and run the following commands to deploy Nginx services.ecs-ipv4
sudo yum install -y nginx sudo systemctl start nginx echo "Hello from IPv4 backend" | sudo tee /usr/share/nginx/html/index.htmlecs-ipv6
sudo yum install -y nginx sudo systemctl start nginx echo "Hello from IPv6 backend" | sudo tee /usr/share/nginx/html/index.html -
Add inbound rules to the security groups of both ECS instances to allow inbound traffic on port 80. Make sure the rules have a high enough priority.
Instance Name
Action
Protocol
Source
Destination
ecs-ipv4
Allow
Custom TCP
After you select
IPv4, selectCIDR block of this VPC.After you select
Port Range, selectHTTP (80).ecs-ipv6
After you select
IPv6, selectCIDR block of this VPC.
For more information, see Create an instance by using the wizard, Connect to an ECS instance, and Add security group rules.
2. Create a dual-stack NLB instance
-
Log on to the NLB console, select the China (Shanghai) region, and then click Create NLB.
-
Specify the following parameters, keep the default values for other options, and then click Create:
-
Network Type: Select Public.
-
VPC: Select
VPC1. -
Zone: Select availability zones E and G, select the corresponding vSwitches
VSW1andVSW2, and select Purchase EIP. -
IP Version: Select Dual-Stack.
-
-
After the instance is created, click the instance ID to go to the Instance Details page. In the Basic Information section, find Network Type, and click Change Network Type to the right of IPv6: Private. In the dialog box that appears, click OK. Then, verify that the IPv6 network type is now public.
3. Create a dual-stack server group and enable affinity
-
In the Server Group console, click Create Server Group.
-
Specify the following parameters and click Create:
-
Server Group Type: Select Server.
-
Server Group Name: Enter
sgp-dualstack. -
VPC: Select
VPC1. -
Backend Server Protocol: Select TCP.
-
IP Version: Select IPv4/IPv6 dual-stack. This allows you to add both IPv4 and IPv6 backend servers.
-
IP Version Affinity: Select Affinity mode. When enabled, IPv4 requests are forwarded only to IPv4 backend servers, and IPv6 requests are forwarded only to IPv6 backend servers.
-
-
In the The server group is created dialog box, click Add Backend Server. In the IP column, select the IPv4 address for
ecs-ipv4and the IPv6 address forecs-ipv6. Select both instances and click Next.When you add IPv6 backend servers in batches, click the settings icon next to the IP column header and select Prefer IPv6 over IPv4. The system then selects the IPv6 addresses of servers by default.
-
In the Ports/Weights step, set the Port for both servers to
80and click OK.
4. Create a listener
-
In the NLB console, click the ID of the target instance to go to the Instance Details page. On the Listener tab, click Create Listener.
-
In the Configure Listener step, set Listener Protocol to TCP, enter
80for Listener Port, and then click Next. -
In the Select Server Group step, select the
sgp-dualstackserver group and click Next. -
In the Configuration Review step, confirm the configuration and click Submit.
5. Configure DNS records
Create a CNAME record to map your custom domain name to the DNS name of the NLB instance.
This tutorial uses Alibaba Cloud DNS as an example. If your domain name is not registered with Alibaba Cloud, you must first add the domain name to the Alibaba Cloud DNS console.
-
In the NLB console, copy the Domain Name of the target instance.
-
Log on to the Alibaba Cloud DNS console. In the Actions column of your target domain name, click Settings. On the Settings page, click Add Record.
-
Add a CNAME record with the following settings and click OK:
-
Record Type: Select CNAME.
-
Hostname: Enter a prefix for the domain name, such as
test. If your root domain name isexample.com, the domain name used to access the NLB instance istest.example.com. -
Query Source and TTL: Keep the default values.
-
Record Value: Enter the DNS name of the NLB instance.
-
-
In the Change Resource Record Confirmation dialog box, confirm the DNS record information and click OK.
6. Verify affinity-based forwarding
When a client accesses the dual-stack NLB instance through a custom domain name, the DNS server returns an A record (IPv4) or AAAA record (IPv6) based on the client's IP version.
Test IPv4 requests
curl -4 http://test.example.com
After multiple requests, the response should always be Hello from IPv4 backend. This indicates that IPv4 requests are forwarded to the IPv4 backend server ecs-ipv4.
Test IPv6 requests
curl -6 http://test.example.com
After multiple requests, the response should always be Hello from IPv6 backend. This indicates that IPv6 requests are forwarded to the IPv6 backend server ecs-ipv6.
Verify affinity isolation
-
Stop the Nginx service on
ecs-ipv4by running the following command:sudo systemctl stop nginx. -
Test the IPv4 request again. The request fails and is not forwarded to the IPv6 backend server
ecs-ipv6. -
Restore the service on
ecs-ipv4by running the following command:sudo systemctl start nginx. IPv4 requests now work as expected.
More information
Billing
-
NLB instance: NLB supports two billing methods: pay-as-you-go and resource plan. For more information, see NLB billing.
-
ECS instance: For more information, see ECS billing overview. For testing, create a low-specification pay-as-you-go instance and release it after testing to avoid unnecessary charges.
-
Domain name and DNS resolution fees: In addition to the domain name fee from your provider, Alibaba Cloud charges public authoritative DNS fees for DNS resolution.
-
Public network fees: Public network fees apply to the EIP associated with the NLB instance and the IPv6 public bandwidth of the VPC where the instance resides.
Supported regions for dual-stack NLB
|
Area |
Region |
|
China |
China (Hangzhou), China (Beijing), China (Shenzhen), China (Shanghai), China (Qingdao), China (Zhangjiakou), China (Chengdu), China (Guangzhou), China (Hong Kong), China (Heyuan), and China (Ulanqab) |
|
Asia Pacific |
Thailand (Bangkok), Philippines (Manila), Singapore, Japan (Tokyo), South Korea (Seoul), Malaysia (Kuala Lumpur), and Indonesia (Jakarta) |
|
Europe and Americas |
Germany (Frankfurt), UK (London), France (Paris), US (Virginia), US (Silicon Valley), and Mexico |
|
Middle East |
SAU (Riyadh - Partner Region) |
Production environment considerations
-
High-availability deployment: Deploy backend servers across multiple availability zones. Ensure redundancy for both IPv4 and IPv6 backends to prevent single points of failure.
-
Health check configuration: Adjust the health check interval, timeout period, and thresholds based on your business requirements to ensure that unhealthy servers are promptly removed.
FAQ
Are IPv4 requests forwarded to IPv6 backends in affinity mode?
No. When affinity mode is enabled, IPv4 requests are forwarded only to IPv4 backend servers, and IPv6 requests are forwarded only to IPv6 backend servers. Cross-protocol forwarding does not occur.
How are IPv6 requests handled with only IPv4 backends?
If affinity mode is disabled, NLB can translate IPv6 requests to IPv4 and send them to the backend servers. If affinity mode is enabled, IPv6 requests cannot be forwarded. In this scenario, you must add backend servers for both IP versions to the server group to ensure that both IPv4 and IPv6 requests are processed.
Can I modify a server group's IP version?
No. The IP protocol version of a server group (IPv4 or IPv4/IPv6 dual-stack) cannot be modified after the server group is created. To change the version, you must delete the server group and create a new one.
Can I modify the IP version affinity of a server group?
Yes. In the Server Group console, find the target dual-stack server group and click Modify Basic Information in the Actions column to modify the setting.
Can a dual-stack server group be associated with an IPv4-only NLB?
No. A dual-stack server group can be associated only with a listener of a dual-stack NLB instance.