Help Center/ Elastic Load Balance/ Best Practices/ Advanced Functions/ Using a NAT Gateway SNAT Rule to Enable a Dedicated Load Balancer to Forward Traffic to a Backend Server with a Public IP Address
Updated on 2026-10-20 GMT+08:00

Using a NAT Gateway SNAT Rule to Enable a Dedicated Load Balancer to Forward Traffic to a Backend Server with a Public IP Address

Application Scenarios

In Huawei Cloud networking scenarios, you can use a dedicated load balancer and a NAT gateway SNAT rule to forward client requests to backend servers over the Internet. This solution uses the IP as a Backend function of the load balancer and the SNAT rule of a NAT gateway to enable the load balancer to forward traffic to backend servers through a public IP address.

Typical scenario

  • Backend servers are located in an on-premises Internet data center (IDC) and need to communicate with the load balancer over the Internet.
  • Backend servers are deployed in another VPC or on another cloud platform and need to be reachable over the Internet.
  • Cross-region or cross-cloud load balancing traffic needs to be distributed over the Internet.

Traffic path

Client → ELB → SNAT → Public IP address → Destination server

Solution Architecture

Architecture description

In this practice, a dedicated load balancer and a NAT gateway are created in the same VPC. The SNAT function of the NAT gateway is used to enable the load balancer to forward traffic to the backend server through a public IP address.

Architecture elements

Component

Description

Dedicated load balancer (ELB-Test)

This dedicated load balancer is created in VPC-Test, with IP as a Backend enabled and an EIP bound to provide services externally.

NAT gateway (NAT-Test)

This NAT gateway is created in VPC-Test, with the SNAT function enabled to provide SNAT capabilities for subnets in the VPC.

SNAT + EIP

The EIP is bound to the NAT gateway, which is used for SNAT to allow private network resources to access the Internet.

Backend destination server

This server is reachable from the Internet and receives requests forwarded by the load balancer through a public IP address.

Client

The client accesses services through the EIP of the load balancer.

Traffic forwarding process
  1. The client initiates a request to access the EIP (ELB-EIP) bound to the load balancer.
  2. The load balancer receives the request and forwards the request to the IP as a backend (public IP address of the backend server) based on the listener and backend server group configuration.
  3. The traffic forwarded by the load balancer passes through the VPC internal routes and matches the SNAT rule of the NAT gateway.
  4. The NAT gateway (SNAT) translates the private IP address of the load balancer to the SNAT-EIP bound to the NAT gateway.
  5. After the translation, traffic reaches the public IP address of the backend server over the Internet.
  6. The backend server processes the request and returns a response along the same path.

Constraints

  • Only dedicated load balancers support IP as a Backend.
  • IP as a Backend can be enabled only when you create a load balancer. This setting cannot be modified after the load balancer is created.
  • The backend subnet of the load balancer must be included in the SNAT rule of the NAT gateway. Otherwise, traffic will not pass through the SNAT rule.
  • The security group of the backend server must allow access from SNAT-EIP in the inbound direction.
  • You need to select a NAT gateway specification that meets your service requirements to prevent packet loss.
  • The health check traffic of IP as a backend server also passes through the SNAT rule to ensure that the health check path is reachable.

Resource Planning

Resource

Quantity

Description

VPC and subnet

1 VPC and 2 subnets

  • VPC-Test: 172.16.0.0/12
  • subnet-frontend: 172.16.0.0/16
  • subnet-backend: 172.18.0.0/16

Dedicated load balancer

1

This load balancer has IP as a Backend enabled. Its VPC is VPC-Test, frontend subnet is subnet-frontend, and backend subnet is subnet-backend.

CAUTION:

In this solution, do not share the backend subnet of the load balancer with other services. Otherwise, traffic of those services will be forwarded to the public IP address.

NAT gateway

1

This NAT gateway belongs to VPC-Test and has the SNAT function enabled.

EIP

3

  • ELB-EIP is bound to the load balancer to provide services externally.
  • SNAT-EIP is bound to the NAT gateway for SNAT.
  • Client-EIP is bound to the client ECS to access the load balancer over the Internet.

ECS

1

ECS-client is used to simulate client access.

Backend server

1

This server is accessible from the Internet and is used to deploy services (such as Nginx).

Preparations

Before the configuration, ensure that the following preparations are complete:

  1. Create VPC-Test and subnets subnet-frontend and subnet-backend. For details, see Creating a VPC with a Subnet.
  2. Purchase an ECS (ECS-client) as the client and bind an EIP to it. For details, see Purchasing and Using a Linux ECS in Custom Config Mode (New Edition).
  3. Deploy services (such as Nginx) on the backend server that is accessible from the Internet. Ensure that the services are running properly and that the corresponding ports are in the listening state.

Procedure

  1. Create a NAT gateway and configure an SNAT rule.
    1. Go to the Buy Public NAT Gateway page.
    2. Configure parameters as prompted.
      Configure the key parameters as follows:

      Parameter

      Example Value

      Description

      Name

      NAT-Test

      The name of the NAT gateway.

      Specifications

      Small

      Select a specification based on your service traffic requirements.

      VPC

      VPC-Test

      The VPC that the NAT gateway belongs to.

      Subnet

      subnet-backend

      The subnet that the NAT gateway uses.

    3. Click Next and confirm the public NAT gateway configuration on the displayed page.
    4. Confirm the configuration and click Submit.
    5. Click the name of the purchased NAT gateway to go to the summary page.
    6. On the SNAT Rules tab, click Add SNAT Rule.
      Configure the key parameters as follows:

      Parameter

      Example Value

      Description

      EIP

      SNAT-EIP

      Select or purchase an EIP for SNAT.

      CIDR Block

      subnet-backend

      Select the subnet that requires SNAT (Load balancer backend subnet).

      CAUTION:

      In this solution, do not share the backend subnet of the load balancer with other services. Otherwise, traffic of those services will be forwarded to the public IP address.

    1. Click OK.

      After the SNAT rule is added, the source IP addresses of the resources in subnet-backend are translated to SNAT-EIP when the resources access the Internet.

  2. Create a dedicated load balancer with IP as a Backend enabled.
    1. Go to the Buy Elastic Load Balancer page.
    2. Configure parameters as prompted.
      Configure the key parameters as follows:

      Parameter

      Example Value

      Description

      Type

      Dedicated load balancer

      Select Dedicated load balancer. Only dedicated load balancers support IP as a Backend.

      Name

      ELB-Test

      The load balancer name.

      VPC

      VPC-Test

      The same VPC as the NAT gateway.

      Frontend Subnet

      subnet-frontend

      The subnet used by the load balancer to receive requests from clients.

      Backend Subnet

      subnet-backend

      The subnet used by the load balancer to forward traffic. This subnet must match the SNAT rule of the NAT gateway.

      IP as a Backend

      Enable

      This function must be enabled to add IP addresses as backend servers.

      Network Type

      Private IPv4 network

      Select Private IPv4 network. You also need to bind an EIP to the load balancer for Internet access.

      EIP

      ELB-EIP

      Purchase an EIP or use an existing one.

      • IP as a Backend cannot be modified after the load balancer is created. It must be enabled during load balancer creation.
      • The backend subnet of the load balancer must be the same as the subnet included in the SNAT rule of the NAT gateway. This ensures that the traffic forwarded by the load balancer matches the SNAT rule.
    3. Click Buy Now.
  3. Create a backend server group and add an IP address as the backend server.
    1. Go to the backend server group list page.
    2. Click Create Backend Server Group in the upper right corner of the page.
    3. Configure the backend routing policy.
      Configure the key parameters as follows:

      Parameter

      Example Value

      Description

      Backend Server Group Name

      server_group

      The name of the backend server group.

      Type

      Dedicated

      The type must match that of the load balancer.

      Load Balancer

      Associate existing

      Select a created load balancer.

      Backend Protocol

      HTTP

      Select a protocol based on the backend service protocol. The options are HTTP, HTTPS, TCP, UDP, and more.

      Load Balancing Algorithm

      Weighted round robin

      The load balancing algorithm.

    4. Click Next to add backend servers and configure health check.
    5. Switch to the IP as Backend Servers tab and click Add.
    6. On the page for adding IP addresses as backend servers, configure related parameters.

      Parameter

      Example Value

      Description

      IP Address

      x.x.x.x

      Enter the public IP address of the backend server. The load balancer forwards traffic based on this IP address.

      Backend Port

      80

      The listening port of the backend server.

      Weight

      1

      The weight of the backend server. The default value is 1.

    1. Click OK.
    2. Enable health check and retain the default values for other health check parameters.
    3. Click Next. After confirming that the configuration is correct, click Create Now.
  4. Add a listener and select the created backend server group.
    1. Go to the load balancer list page.
    2. Locate the row that contains the target load balancer and click Add Listener in the Operation column.
      Configure the key parameters as follows:

      Parameter

      Example Value

      Description

      Frontend Protocol

      HTTP

      The protocol used by the listener to receive requests.

      Listening Port

      80

      The port used by the listener to receive requests.

    3. Click Next: Configure Backend Routing Policy.
    4. For Backend Server Group, select Use existing and select server_group created in 3.
    5. Click Next: Confirm.
    6. Confirm the configuration and click Submit.
  5. (Optional) Configure the security groups and network ACLs.

    Ensure that the following network access policies have been correctly configured based on service requirements:

    Direction

    Source/Destination

    Protocol

    Port

    Description

    Inbound

    0.0.0.0/0

    TCP

    80

    The security group and network ACL of the load balancer allow requests from the client.

    Outbound

    0.0.0.0/0

    TCP

    80

    The load balancer allows requests to be forwarded to backend servers.

    Inbound (Backend server)

    SNAT-EIP

    TCP

    80

    The backend server allows requests from SNAT-EIP.

    After traffic forwarded by the load balancer is translated by the SNAT rule of the NAT gateway, the source IP address seen by the backend server is SNAT-EIP. Therefore, the security group of the backend server must allow access from SNAT-EIP.

Configuration Verification

  • Verifying the configuration using the client ECS
    1. Remotely log in to ECS-client.
    2. Run the following command to test the connectivity:

      curl -v http://<EIP-of-the-load-balancer>:<Listening-port>

    1. If a response from the backend server is received, such as the default Nginx welcome page, it indicates that the load balancer has successfully forwarded the request to the backend server over the Internet.
  • Verifying the configuration using a browser

    Use a browser to access http://<EIP-of-the-load-balancer>. If the service content of the backend server is displayed, it indicates that the load balancer has successfully forwarded the request to the backend server through SNAT.

  • Verifying SNAT

    Check the access logs on the backend server. If the source IP address of the request is SNAT-EIP of the NAT gateway rather than the private IP address of the load balancer, the traffic has been translated by the SNAT rule of the NAT gateway.

Common Issues

  • There is no response when the client accesses the load balancer.
    • Check whether the load balancer listener is correctly configured.
    • Check whether ELB-EIP is bound successfully.
    • Check whether an IP as a backend server has been added to the backend server group.
  • The health check result is abnormal.
    • Check whether the backend server is running properly and listening on the corresponding port.
    • Check whether the security group of the backend server allows access from SNAT-EIP.
    • Check whether the protocol and port configured for the health check are the same as those of the backend service.
  • The backend server cannot receive requests.
    • Ensure that the SNAT rule of the NAT gateway is correctly configured and includes the backend subnet of the load balancer.
    • Ensure that the NAT gateway is in the running status.
    • Capture packets on the backend server to check whether there are requests from SNAT-EIP.
  • The latency of the request response is high.
    • Communication over the Internet typically has higher latency than communication over a direct connection through a private network.
    • Check whether the NAT gateway specifications meet the traffic requirements.
    • Check whether the backend server is overloaded.