Obtain client IP address through a network load balancer (TCP socket server, Python)

0

Hi All,

I run a couple of TCP socket server on EC2, behind a network load balancer (NLB). even I've set the target_group to preserve client IP address. I am not able to obtain the actual client IP address in my Python TCP socket server. All I am getting seems to be a few fixed IP address, likely belong to the load balancer or some edge computing node ?

when I bypass the load balancer, my server app is able to obtain the proper client IP address.

any idea, what I am missing here ?

已提問 2 年前檢視次數 3435 次
2 個答案
3

More info on this topic:

  • For Network Load Balancers, register your targets by instance ID to capture client IP addresses without additional web server configuration. For instructions, see Target group attributes instead of the following resolutions (refer the link)

  • For Network Load Balancers when you can register only IP addresses as targets, enable proxy protocol version 2 on the load balancer. For instructions, see Enable proxy protocol instead of the following resolutions.

Reference: https://aws.amazon.com/premiumsupport/knowledge-center/elb-capture-client-ip-addresses/

profile pictureAWS
專家
已回答 2 年前
profile picture
專家
已審閱 1 個月前
  • Yes,I've tested, it's working in my setup

  • thanks, but this is not relevant to me , I am using Network Loadbalancer

  • Thanks for the clarification, I modified the answer, the link I provided has information for NLB as well.

  • thank you.

0

Behaviour depends on the type of ELB - NLB preserves Source IP (except for IP Address targets), whereas servers behind CLB & ALB see load balancer IPs as Source IPs in client requests and rely on x-forwarded-for header to indicate true source.

專家
已回答 2 年前
  • this is where the confusing part is:

    I am using NLB, and I am seeing a few IP addresses (all my client connection seems all come from these few IP address based on the TCP server log). but reality is I have thousands of client accessing, and they are definitely not from these few IP addresses.

    when I by pass the NLB, I see the correct IP address for the Client

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南