Getting real ip with Network Load Balancer

684 views
Skip to first unread message

류성훈

unread,
Jul 31, 2016, 2:32:12 AM7/31/16
to gce-discussion
I want to get my real ip (not cloudflare and load balancer).
So I have put this source to nginx.conf

# Last updated Sat Jul 30 11:17:32 UTC 2016

set_real_ip_from 103.21.244.0/22;

set_real_ip_from 103.22.200.0/22;

set_real_ip_from 103.31.4.0/22;

set_real_ip_from 104.16.0.0/12;

set_real_ip_from 108.162.192.0/18;

set_real_ip_from 131.0.72.0/22;

set_real_ip_from 141.101.64.0/18;

set_real_ip_from 162.158.0.0/15;

set_real_ip_from 172.64.0.0/13;

set_real_ip_from 173.245.48.0/20;

set_real_ip_from 188.114.96.0/20;

set_real_ip_from 190.93.240.0/20;

set_real_ip_from 197.234.240.0/22;

set_real_ip_from 198.41.128.0/17;

set_real_ip_from 199.27.128.0/21;

set_real_ip_from 2400:cb00::/32;

set_real_ip_from 2405:8100::/32;

set_real_ip_from 2405:b500::/32;

set_real_ip_from 2606:4700::/32;

set_real_ip_from 2803:f800::/32;

set_real_ip_from 130.211.0.0/22; #Google IP


real_ip_header X_Forwarded_For; #CF-Connecting-IP;




To check my ip, I made simple rails source.

return render :json => {:ip => request.ip, :remote_ip => request.remote_ip, :x_forwarded_for => request.env['HTTP_X_FORWARDED_FOR'], :client_ip => request.env['HTTP_CLIENT_IP'], :cf => request.env['CF-Connecting-IP']}

{"ip":"130.211.0.145","remote_ip":"130.211.0.145","x_forwarded_for":"(REAL IP), 141.101.85.141, 130.211.16.204, 130.211.0.145","client_ip":null,"cf":null}

But ip was not my ip, it's LoadBalancer's. What I was wrong?  I tried a lot of time over 6 hours.




 

류성훈

unread,
Jul 31, 2016, 12:05:19 PM7/31/16
to gce-discussion
I resolved this problem.

put this line

set_real_ip_from 130.211.0.0/16;


real_ip_header X-Forwarded-For;


real_ip_recursive on;




2016년 7월 31일 일요일 오후 3시 32분 12초 UTC+9, 류성훈 님의 말:

Kamran (Google Cloud Support)

unread,
Jul 31, 2016, 4:38:17 PM7/31/16
to gce-discussion
Hello,

I'm glad that you've resolved the issue and thanks for sharing your solution. This can help other people who are facing the same problem.

Sincerely,
Reply all
Reply to author
Forward
0 new messages