All Products
Search
Document Center

Server Load Balancer:Obtaining client IP addresses through a CLB Layer 4 listener

Last Updated:Jun 21, 2026

A Classic Load Balancer (CLB) Layer 4 listener lets backend servers obtain the client IP address. In most cases, this happens directly without additional configuration. However, for an IPv6 client to access an IPv4 service, you must enable Proxy Protocol on both the CLB listener and the backend server to retrieve the client IP address.

How it works

image.png

Direct retrieval

A CLB Layer 4 listener typically operates in passthrough mode. In this mode, the source IP address that the backend server receives is the client's actual IP address.

However, this method is ineffective in certain scenarios. In these cases, you must configure Proxy Protocol to retrieve the client IP address. For more information, see Using Proxy Protocol to obtain client IP addresses.

Obtaining client IP addresses via Proxy Protocol

Proxy Protocol is a communication protocol that passes a client's original network connection information between a proxy server and a backend server.

Typically, when a proxy server forwards a client request to a backend server, it rewrites the request header, replacing the client's source IP address and port with its own.

By using Proxy Protocol, the proxy server encapsulates the client's original network connection information in the request header and sends it to the backend server. The backend server can then parse the Proxy Protocol header to obtain the client's real network connection information, including the source IP address, source port, and transport protocol.

Proxy Protocol enables backend servers to accurately obtain original client connection information for more precise logging, access control, and traffic monitoring.

Important
  • For Proxy Protocol to work, both the proxy server and the backend server must support it. Enabling this feature on a backend server that cannot parse the Proxy Protocol header may cause parsing errors and affect service availability.

  • A CLB Layer 4 listener can use Proxy Protocol to carry original connection information, including the source IP, destination IP, source port, and destination port. This information is prepended to the TCP or UDP data header without discarding or overwriting existing data.

  • CLB supports only Proxy Protocol v2. Proxy Protocol v2 supports multiple transport protocols, such as TCP and UDP. For more information, see The PROXY protocol.

When IPv6 clients access IPv4 services behind a CLB instance, you must enable Proxy Protocol on both the CLB Layer 4 listener and the backend services to retrieve the client IP address.

Procedure

Direct retrieval

In this scenario, you can obtain the client IP address directly from the backend server.

If you use Nginx as the backend server, you can check the Nginx logs to verify that the client's IP address was captured correctly.

The following example shows the default log field configuration for Nginx:

http {
  # Default configuration
  log_format  main  '$remote_addr- $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
	#...
}

The default path for the Nginx log file is /var/log/nginx/access.log.

The first IP address in each log entry is the client's real IP address.

140.205.1xxx - - [xxx, xxx] xxx xxx xxx xxx xxx xxx
xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx
140.205.xx.29 - [27/xxx xxx] xxx xxx xxx xxx xxx xxx xxx
xxx xxx xxx xxx xxx xxx xxx xxx xxx
140.205.xx.29 - - [2xxx xxx] 304 xxx xxx xxx xxx xxx xxx

Proxy Protocol

Prerequisites

  • You have created a CLB instance and added a listener to it. This topic uses a TCP listener on port 80 as an example. For more information, see Create and manage CLB instances and Add a TCP listener.

  • You have created an available server group for the CLB instance and added backend servers to it. This topic uses a vServer group with TCP as the backend protocol and ECS instances that listen on port 80 as backend servers. For more information, see Create and manage a vServer group.

    Note
    • Before you enable Proxy Protocol, make sure your backend servers support Proxy Protocol v2. Otherwise, new connections may fail.

    • Nginx Plus R16 or later and open-source Nginx 1.13.11 or later support Proxy Protocol v2.

    • If multiple listeners of a CLB instance are associated with the same group of backend servers, you must enable Proxy Protocol for all of these listeners.

Step 1: Enable Proxy Protocol for the listener

  1. Log on to the Classic Load Balancer (CLB) console.

  2. In the top navigation bar, select the region where the CLB instance is deployed.

  3. On the Instances page, find the target instance and click its ID.

  4. On the instance details page, click the Listener tab, find the target Layer 4 listener and click its ID.

  5. On the listener details page, check if the Proxy Protocol parameter is set to Use the Proxy protocol to pass client IP addresses to backend servers.. If this parameter is not displayed, click Modify Listener and enable the feature on the configuration page.

    Important

    This feature does not support seamless migration. Enabling Proxy Protocol requires a service restart to apply the changes. Proceed with caution.

Step 2: Enable Proxy Protocol on the backend

This section uses a server with CentOS 7.9 and Nginx 1.20.1 as an example. The configurations may vary based on your environment.

  1. Log on to a backend server and run the nginx -t command to find the path of the configuration file. The default path is typically /etc/nginx/nginx.conf. The actual path may vary.

  2. Modify the Proxy Protocol settings in the configuration file and save the changes. Refer to the following example for the modifications:

    http {
      # Make sure to set $proxy_protocol_addr.
      log_format  main  '$proxy_protocol_addr - $remote_addr- $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';
      # Use port 80 as an example and add the proxy_protocol parameter.
      server {
        listen 80   proxy_protocol;
        #...
      }
    }
                
  3. Run the sudo nginx -s reload command to reload the Nginx configuration file.

Step 3: Verify the result

If Nginx is used as the backend server, you can check the Nginx logs to verify whether the client's real IP address is successfully obtained.

The default path for the Nginx log file is /var/log/nginx/access.log.

In each log entry, the IP address corresponding to the $proxy_protocol_addr variable is the client's real IP address.

Proxy Protocol v2 header formats

If you do not use the server in the preceding example, you can refer to the Proxy Protocol v2 header formats and The PROXY protocol to implement custom parsing. For details, see the official documentation for your server.

  • The following figure shows the binary header format for Proxy Protocol v2 that carries a client IPv4 address:IPv4

  • The following figure shows the binary header format for Proxy Protocol v2 that carries a client IPv6 address:IPv6

FAQ

Frequent access from IPs starting with 100

The load balancing system forwards external requests to backend ECS instances and performs health checks. Both types of requests originate from the system.

The load balancing system uses the reserved CIDR block 100.64.0.0/10. This block is exclusive to Alibaba Cloud and poses no security risk, but explains the frequent access from IPs starting with 100.

Ensure that iptables and other security software on your servers do not block this CIDR block.

Getting client IPs in an ACK environment

In a Container Service for Kubernetes (ACK) cluster, the method is the same but some operational details differ. Network management FAQ.

Related documents

The method for obtaining client IP addresses varies by load balancer type: