Verifying Google Cloud egress IP ranges with cloud.json and jq
When GCE workloads or Cloud NAT gateways connect to external partner endpoints, it is common to run into asymmetric reachability issues - connections from one region work normally, while connections from another region (or from a newly reserved NAT IP in the same region) time out on the initial TCP SYN . In most cases, this happens because the destination firewall uses a static IP allowlist that…
Google Cloud egress IP ranges can be verified with the cloud.json feed, which is a machine-readable list of all customer-usable external IPv4 and IPv6 ranges by region. To check your reserved external IPs against this feed, you can use the gcloud compute addresses list command to grab your reserved external IPs as JSON and then use jq to match each IP against the published CIDR ranges in cloud.json.
In the example provided, the script checks the reserved external IPs in the us-south1 region against the cloud.json feed. The reserved IPs in this region are checked and mapped to their parent CIDR blocks and regional scope in cloud.json. For instance, nat-ip-a0 and nat-ip-a1 are both mapped to the 34.174.0.0/16 CIDR block in the us-south1 region, while nat-ip-a2 is mapped to the 34.0.128.0/19 CIDR block in the same region.
The cloud.json feed includes information about each IPv4 range, such as the IPv4 prefix, the service (Google Cloud in this case), and the scope (us-south1 in this example). The script converts the IPv4 address string into a 32-bit integer for CIDR matching, allowing it to compare each IP address against its corresponding CIDR block in cloud.json.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to