How does the source IP appear behind ALB, NLB and Cloudflare?
IntermediateConceptLoad Balancers, Proxies & CDNs
Answer
Behind an ALB, the backend sees the ALB's IP and gets the client in X-Forwarded-For. NLB preserves the client IP for instance targets (not for IP targets by default, where you can use PROXY protocol v2). Behind Cloudflare, use CF-Connecting-IP or X-Forwarded-For and trust only Cloudflare's published ranges.
Security groups on backends should allow the LB security group, not the internet.
More on Load Balancers, Proxies & CDNs
What is a load balancer and why do we use one?BeginnerWhat is the difference between L4 and L7 load balancing?IntermediateCompare ALB, NLB, GWLB and Classic Load Balancer in AWS.IntermediateWhat load-balancing algorithms are common?BeginnerWhat are health checks and how should they be designed?AdvancedWhat is connection draining (deregistration delay)?Intermediate