- Newest
- Most votes
- Most comments
When using AWS Network Load Balancer (NLB) with client IP preservation enabled, you're observing a behavior that resembles Direct Server Return (DSR) but with some important AWS-specific differences.
With client IP preservation enabled, the NLB preserves the original client's IP address when forwarding traffic to targets. This means your EC2 instance sees the client's original IP address rather than the NLB's private IP address. This is beneficial for applications that need to know the true source of traffic.
However, unlike traditional DSR where return traffic bypasses the load balancer completely, in AWS's implementation, the return traffic from your EC2 instance still flows through the NLB. This happens through AWS's underlying network infrastructure and the Hyperplane technology that powers NLB.
The mechanism works as follows:
- Client sends traffic to the NLB's public IP address
- NLB forwards this traffic to the target EC2 instance while preserving the client's original IP address
- The EC2 instance processes the request and sends response packets addressed to the client's IP
- AWS's network infrastructure ensures these return packets are routed through the NLB before reaching the client
This routing behavior is enforced at the AWS network level, not at the EC2 instance level. The EC2 instance doesn't need to be aware of the NLB's IP address because AWS's network infrastructure handles the routing. This is part of the "flow symmetry" that AWS maintains for NLB connections.
It's worth noting that client IP preservation has specific requirements:
- For IPv4 clients, it works when the target is in the same VPC as the NLB or in a peered VPC
- For IPv6 clients connecting to IPv6 targets, client IP is always preserved
- For cross-protocol scenarios (IPv4 to IPv6 or vice versa), the source IP will always be the NLB's private IP
If client IP preservation isn't possible or enabled, the EC2 instance will see the NLB's private IP address as the source. In cases where you need the client IP but can't use client IP preservation, you can enable proxy protocol, which adds the client IP information to the TCP payload.
Sources
Scaling the dual-stack network design in AWS - IPv6 on AWS
ELB client IP address | AWS re:Post
Relevant content
asked 6 years ago
