Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Die ausgehenden Dienste in der App Engine-Standardumgebung, wie die URL Fetch API, die Sockets API und die Mail API, verwenden einen großen Pool von IP-Adressen. Die IP-Adressbereiche in diesem Pool unterliegen regelmäßigen Änderungen. Bei zwei aufeinanderfolgenden API-Aufrufen derselben Anwendung kann beispielsweise der Eindruck entstehen, sie stammten von zwei verschiedenen IP-Adressen.
Wenn Sie die IP-Adressen kennen müssen, die mit dem ausgehenden Traffic von Ihrem Dienst verknüpft sind, können Sie entweder die aktuellen IP-Adressbereiche für Ihren Dienst ermitteln oder eine statische IP-Adresse für Ihren Dienst einrichten.
IP-Adressen für App Engine-Dienste
Sie können die aktuellen IP-Adressbereiche für Ihre App Engine-Dienste anhand der von Google veröffentlichten IP-Bereichsinformationen ermitteln:
Google veröffentlicht die vollständige Liste der IP-Bereiche, die Nutzern im Internet zur Verfügung stehen, in goog.json.
Außerdem veröffentlicht Google in der Datei cloud.json eine Liste globaler und regionaler externer IP-Adressbereiche, die für die Google Cloud -Ressourcen des Kunden verfügbar sind.
Die von Google APIs und Diensten verwendeten IP-Adressen liegen innerhalb der Bereiche, die verbleiben, nachdem die Bereiche aus cloud.json aus denen in goog.json entfernt wurden. Diese Listen werden häufig aktualisiert.
Mit dem folgenden Python-Skript können Sie eine Liste der IP-Adressbereiche erstellen, die die von Google APIs und Diensten verwendeten enthalten.
Weitere Informationen zum Ausführen dieses Skripts finden Sie unter Ausführung.
from__future__importprint_functionimportjsontry:fromurllibimporturlopenexceptImportError:fromurllib.requestimporturlopenfromurllib.errorimportHTTPErrorimportnetaddrIPRANGE_URLS={"goog":"https://www.gstatic.com/ipranges/goog.json","cloud":"https://www.gstatic.com/ipranges/cloud.json",}defread_url(url):try:returnjson.loads(urlopen(url).read())except(IOError,HTTPError):print("ERROR: Invalid HTTP response from %s"%url)exceptjson.decoder.JSONDecodeError:print("ERROR: Could not parse HTTP response from %s"%url)defget_data(link):data=read_url(link)ifdata:print("{} published: {}".format(link,data.get("creationTime")))cidrs=netaddr.IPSet()foreindata["prefixes"]:if"ipv4Prefix"ine:cidrs.add(e.get("ipv4Prefix"))if"ipv6Prefix"ine:cidrs.add(e.get("ipv6Prefix"))returncidrsdefmain():cidrs={group:get_data(link)forgroup,linkinIPRANGE_URLS.items()}iflen(cidrs)!=2:raiseValueError("ERROR: Could process data from Google")print("IP ranges for Google APIs and services default domains:")foripin(cidrs["goog"]-cidrs["cloud"]).iter_cidrs():print(ip)if__name__=="__main__":main()
Statische ausgehende IP-Adresse einrichten
Verwenden Sie zum Einrichten einer statischen IP-Adresse für den Dienst der App Engine-Standardumgebung den serverlosen VPC-Zugriff mit Cloud Router und Cloud NAT. Mit dem serverlosen VPC-Zugriff können Sie ausgehenden Traffic an Ihr VPC-Netzwerk (Virtual Private Cloud) senden. Wenn Sie ein NAT-Gateway (Network Address Translation) in Ihrer VPC verwenden, können Sie den App Engine-Traffic über eine dedizierte IP-Adresse weiterleiten.
Wenn Sie den Traffic über Cloud NAT weiterleiten, wird kein zusätzlicher Hop im Netzwerk-Stack verursacht, da das Cloud NAT-Gateway und der Cloud Router nur eine Steuerungsebene bieten und die Pakete nicht durch das NAT-Gateway oder den Cloud Router weitergeleitet werden.
In den folgenden Schritten wird gezeigt, wie Sie eine statische ausgehende IP-Adresse für Ihren Dienst der App Engine-Standardumgebung einrichten.
Prüfen Sie, ob Sie die Rolle roles/compute.networkAdmin oder eine benutzerdefinierte Rolle mit denselben Berechtigungen haben.
Erstellen Sie ein Subnetzwerk (Subnetz) in Ihrem VPC-Netzwerk für App Engine-Traffic. Dadurch wird vermieden, dass andere Ressourcen in Ihrem VPC-Netzwerk die statische IP-Adresse verwenden können.
SUBNET_NAME durch einen Namen, den Sie dem Subnetz geben möchten
RANGE durch den IP-Bereich im CIDR-Format, den Sie diesem Subnetz zuweisen möchten (z. B. 10.124.0.0/28).
NETWORK_NAME durch den Namen Ihres VPC-Netzwerks.
REGION durch die Region Ihres App Engine-Dienstes.
Verbinden Sie den App Engine-Dienst mit dem Subnetz.
Folgen Sie der Anleitung Verbindung zu einem VPC-Netzwerk herstellen und geben Sie den Namen des Subnetzes an, das Sie im vorherigen Schritt für das Connector-Subnetz erstellt haben.
Erstellen Sie einen neuen Cloud Router. Cloud Router ist eine erforderliche Komponente der Steuerungsebene für Cloud NAT.
ROUTER_NAME durch einen Namen für die Cloud Router-Ressource, die Sie erstellen möchten.
NETWORK_NAME durch den Namen Ihres VPC-Netzwerks.
REGION durch die Region, in der Sie ein NAT-Gateway erstellen möchten.
Reservieren Sie eine statische IP-Adresse.
Dies ist die Adresse, mit der Ihr Dienst ausgehenden Traffic sendet. Eine reservierte IP-Adressressource behält die zugrunde liegende IP-Adresse bei, wenn die ihr zugeordnete Ressource gelöscht und neu erstellt wird. Diese IP-Adresse wird auf die statischen IP-Adresskontingente in Ihrem Google Cloud -Projekt angerechnet.
ORIGIN_IP_NAME durch den Namen, den Sie der IP-Adressressource zuweisen möchten.
REGION durch die Region, in der der Cloud NAT-Router ausgeführt wird. Idealerweise sollten Sie dieselbe Region wie der App Engine-Dienst verwenden, um Latenz und Netzwerkkosten zu minimieren.
Standardmäßig senden App Engine-Dienste, die den serverlosen VPC-Zugriff verwenden, nur internen Traffic an Ihr VPC-Netzwerk. Wenn Sie Traffic mit externen Zielen an Ihr VPC-Netzwerk senden möchten, damit es die von Ihnen angegebene statische IP-Adresse hat, müssen Sie die Einstellung für ausgehenden Traffic ändern.
Geben Sie die Einstellung für ausgehenden Traffic in der app.yaml-Datei für Ihren Dienst an:
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-09-03 (UTC)."],[[["\u003cp\u003eOutbound traffic from App Engine standard environment services uses a dynamic pool of IP addresses, which means successive API calls may originate from different IPs.\u003c/p\u003e\n"],["\u003cp\u003eYou can find the current IP address ranges used by App Engine services by referring to the regularly updated \u003ccode\u003egoog.json\u003c/code\u003e and \u003ccode\u003ecloud.json\u003c/code\u003e files published by Google.\u003c/p\u003e\n"],["\u003cp\u003eA Python script is provided to help determine the specific IP ranges used by Google APIs and services by subtracting \u003ccode\u003ecloud.json\u003c/code\u003e ranges from \u003ccode\u003egoog.json\u003c/code\u003e ranges.\u003c/p\u003e\n"],["\u003cp\u003eTo use a consistent IP address, you can configure a static outbound IP address for your App Engine service by using Serverless VPC Access, Cloud Router, and Cloud NAT, which involves setting up a subnet, connecting to the subnet, creating a router, reserving a static IP, setting up the NAT gateway and changing the egress setting.\u003c/p\u003e\n"]]],[],null,["# Outbound IP addresses for App Engine services\n\nThe outbound services in the App Engine standard environment, such\nas the URL Fetch, Sockets, and Mail APIs, make use of\na large pool of IP addresses. The IP address ranges in this pool are subject to\nroutine changes. In fact, two sequential API calls from the same application may\nappear to originate from two different IP addresses.\n\nIf you need to know the IP addresses associated with outbound traffic from your\nservice, you can either find the current IP address ranges for your service, or\nset up a static IP address for your service.\n\nIP addresses for App Engine services\n------------------------------------\n\nYou can find the current IP address ranges for your App Engine services\nbased on IP range information that Google publishes:\n\n- Google publishes the complete list of IP ranges that it makes available to\n users on the internet in [goog.json](https://www.gstatic.com/ipranges/goog.json).\n\n- Google also publishes a list of global and regional external IP addresses\n ranges available for customers' Google Cloud resources in\n [cloud.json](https://www.gstatic.com/ipranges/cloud.json).\n\nThe IP addresses used by Google APIs and services fit\nwithin the list of ranges computed by taking away all ranges in `cloud.json`\nfrom those in `goog.json`. These lists are updated frequently.\n\nYou can use the following Python script to create a list of IP address ranges\nthat include those used by Google APIs and services.\n\nFor information about running this script, see [How to\nrun](https://github.com/GoogleCloudPlatform/networking-tools-python/tree/main/tools/cidr#how-to-run). \n\n from __future__ import print_function\n\n import json\n\n try:\n from urllib import urlopen\n except ImportError:\n from urllib.request import urlopen\n from urllib.error import HTTPError\n\n import netaddr\n\n IPRANGE_URLS = {\n \"goog\": \"https://www.gstatic.com/ipranges/goog.json\",\n \"cloud\": \"https://www.gstatic.com/ipranges/cloud.json\",\n }\n\n\n def read_url(url):\n try:\n return json.loads(urlopen(url).read())\n except (IOError, HTTPError):\n print(\"ERROR: Invalid HTTP response from %s\" % url)\n except json.decoder.JSONDecodeError:\n print(\"ERROR: Could not parse HTTP response from %s\" % url)\n\n\n def get_data(link):\n data = read_url(link)\n if data:\n print(\"{} published: {}\".format(link, data.get(\"creationTime\")))\n cidrs = netaddr.IPSet()\n for e in data[\"prefixes\"]:\n if \"ipv4Prefix\" in e:\n cidrs.add(e.get(\"ipv4Prefix\"))\n if \"ipv6Prefix\" in e:\n cidrs.add(e.get(\"ipv6Prefix\"))\n return cidrs\n\n\n def main():\n cidrs = {group: get_data(link) for group, link in IPRANGE_URLS.items()}\n if len(cidrs) != 2:\n raise ValueError(\"ERROR: Could process data from Google\")\n print(\"IP ranges for Google APIs and services default domains:\")\n for ip in (cidrs[\"goog\"] - cidrs[\"cloud\"]).iter_cidrs():\n print(ip)\n\n\n if __name__ == \"__main__\":\n main()\n\n| **Note:** In the past, Google Cloud published a list of IP address ranges in the `_spf.google.com` DNS TXT record (and the records it referenced). While this DNS TXT record continues to be accurate for [SPF\n| purposes](https://support.google.com/a/answer/33786), it does not contain the complete set of possible IP address ranges used by Google APIs and services.\n\nSet up a static outbound IP address\n-----------------------------------\n\nTo set up a static IP address for your App Engine standard environment service, use\n[Serverless VPC Access](/vpc/docs/serverless-vpc-access)\nwith Cloud Router and [Cloud NAT](/nat/docs). By using\nServerless VPC Access, you can send egress traffic to your\nVirtual Private Cloud (VPC) network. By using a network address\ntranslation (NAT) gateway on your VPC, you can route\nthe App Engine traffic through a dedicated IP address.\n\nRouting your traffic through Cloud NAT does not cause an additional hop in\nyour networking stack since the Cloud NAT gateway and the Cloud Router\nprovide only a control plane and the packets do not pass through the\nCloud NAT gateway or the Cloud Router.\n| **Note:** Serverless VPC Access and Cloud NAT can both incur costs. Review [Serverless VPC Access pricing](/vpc/pricing#serverless-vpc-pricing) and [Cloud NAT pricing](/vpc/network-pricing#nat-pricing).\n\nThe following steps show how to set up a static outbound IP address for your\nApp Engine standard environment service.\n\n1. Make sure that you have the\n [roles/compute.networkAdmin](/iam/docs/understanding-roles#compute-engine-roles)\n role or a custom role with the same permissions.\n\n2. Create a subnetwork (subnet) inside your VPC network for\n App Engine traffic. This ensures that other resources in your\n VPC network cannot use the static IP address.\n\n ```bash\n gcloud compute networks subnets create SUBNET_NAME \\\n --range=RANGE \\\n --network=NETWORK_NAME \\\n --region=REGION\n ```\n\n In the command above, replace:\n - \u003cvar translate=\"no\"\u003eSUBNET_NAME\u003c/var\u003e with a name you want to give to the subnet.\n - \u003cvar translate=\"no\"\u003eRANGE\u003c/var\u003e with the [IP range](/vpc/docs/subnets#manually_created_subnet_ip_ranges) in CIDR format you want to assign to this subnet (e.g. `10.124.0.0/28`)\n - \u003cvar translate=\"no\"\u003eNETWORK_NAME\u003c/var\u003e with the name of your VPC network.\n - \u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e with the region of your App Engine service.\n3. Connect your App Engine service to the subnet.\n\n Follow the guide\n [Connecting to a VPC network](/appengine/docs/standard/connecting-vpc),\n and specify the name of the subnet you created in the previous step for the\n connector subnet.\n4. Create a new Cloud Router. Cloud Router is a necessary control plane\n component for Cloud NAT.\n\n ```bash\n gcloud compute routers create ROUTER_NAME \\\n --network=NETWORK_NAME \\\n --region=REGION\n ```\n\n In the command above, replace:\n - \u003cvar translate=\"no\"\u003eROUTER_NAME\u003c/var\u003e with a name for the Cloud Router resource you want to create.\n - \u003cvar translate=\"no\"\u003eNETWORK_NAME\u003c/var\u003e with the name of your VPC network.\n - \u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e with the region in which you want to create a NAT gateway.\n5. Reserve a static IP address.\n\n This is the address that your service will use to send outgoing traffic. A\n reserved IP address resource retains the underlying IP address when the\n resource it is associated with is deleted and re-created. This IP address\n counts towards the static IP address quotas in your Google Cloud project. \n\n ```bash\n gcloud compute addresses create ORIGIN_IP_NAME \\\n --region=REGION\n ```\n\n In the command above, replace:\n - \u003cvar translate=\"no\"\u003eORIGIN_IP_NAME\u003c/var\u003e with the name you want to assign to the IP address resource.\n - \u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e with the region that will run the Cloud NAT router. Ideally the same region as your App Engine service to minimize latency and network costs.\n\n Use the [`compute addresses describe` command](/sdk/gcloud/reference/compute/addresses/describe)\n to view the result: \n\n ```\n gcloud compute addresses describe ORIGIN_IP_NAME\n ```\n6. Create a Cloud NAT gateway and specify your IP address.\n\n Traffic originating from your subnet will go through this gateway and use\n the static IP address that you reserved in the previous step. \n\n ```bash\n gcloud compute routers nats create NAT_NAME \\\n --router=ROUTER_NAME \\\n --region=REGION \\\n --nat-custom-subnet-ip-ranges=SUBNET_NAME \\\n --nat-external-ip-pool=ORIGIN_IP_NAME\n \n ```\n\n In the command above, replace:\n - \u003cvar translate=\"no\"\u003eNAT_NAME\u003c/var\u003e with a name for the Cloud NAT gateway resource you want to create.\n - \u003cvar translate=\"no\"\u003eROUTER_NAME\u003c/var\u003e with the name of your Cloud Router.\n - \u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e with the region in which you want to create a NAT gateway.\n - \u003cvar translate=\"no\"\u003eORIGIN_IP_NAME\u003c/var\u003e with the name of the reserved IP address resource you created in the previous step.\n7. Set the Serverless VPC Access\n [egress setting](/appengine/docs/standard/connecting-vpc#egress)\n to `all-traffic`.\n\n By default, App Engine services that use\n Serverless VPC Access only send internal traffic to your\n VPC network. In order to send traffic with external\n destinations to your VPC network so that it will have the\n static IP address that you specified, you must change the egress setting.\n\n Specify the egress setting in the\n [`app.yaml`](/appengine/docs/standard/reference/app-yaml)\n file for your service: \n\n ```yaml\n vpc_access_connector:\n name: projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e/locations/\u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e/connectors/\u003cvar translate=\"no\"\u003eCONNECTOR_NAME\u003c/var\u003e\n egress_setting: all-traffic\n ```\n\n Replace:\n - \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e with your Google Cloud project ID.\n - \u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e with the region your connector is in.\n - \u003cvar translate=\"no\"\u003eCONNECTOR_NAME\u003c/var\u003e with the [name](/appengine/docs/standard/connecting-vpc#create-connector) of your connector.\n\nDeploy the service: \n\n```bash\n gcloud app deploy\n```"]]