How to determine the IP ranges used by the GCP load balancers
I am operating several VM instances on Google Cloud Platform (GCP). They are behind an HTTP(S) load balancer.
In order to restrict the access based on the origin IP address, I configured the Nginx on each VM instance as follows:
server {
listen 80;
listen [::]:80;
server_name www.example.com;
real_ip_header X-Forwarded-For;
real_ip_recursive on;
set_real_ip_from 130.211.0.0/22; # GCP load balancers
set_real_ip_from 35.191.0.0/16; # GCP load balancers
...
}
I found the IP ranges 130.211.0.0/22
and 35.191.0.0/16
on the Firewall rules section of "HTTP(S) Load Balancing Concepts" document page.
But, in the actual operation, I noticed that accesses could come from another IP range 35.190.0.0/17
.
So, I consulted a section of the Google Compute Engine FAQ and I learned that I can get the list of all public IP ranges of GCP.
This list is very long and seems to include the IP ranges that are not used by the load balancers.
I have two questions:
- How can I determine the IP ranges used by the GCP load balancers?
- How can I update the Nginx configuration when the IP ranges change?