Wenn sich Ihre Quelldatenbank in einem VPN befindet (z. B. in AWS oder in Ihrem lokalen VPN), müssen Sie auch auf der Zielseite ein VPN verwenden, um eine Verbindung zur Quelle herzustellen.
Es gibt viele VPN-Produkte, die Sie verwenden können. Die Schritte zur Konfiguration von VPNs unterscheiden sich von Produkt zu Produkt, sind aber im Grunde ähnlich. Dieser Abschnitt enthält Beispiele für die Verwendung von AWS und Google Cloud VPNs.
Die Firewall des Quelldatenbankservers muss so konfiguriert sein, dass sie den gesamten internen IP-Adressbereich zulässt, der für die private Dienstverbindung des VPC-Netzwerk zugewiesen ist, das die Cloud SQL-Zielinstanz als Feld privateNetwork ihrer ipConfiguration-Einstellungen verwendet.
So finden Sie den internen IP-Bereich in der Console:
Google Cloud Erstellen Sie ein Cloud-VPN mit statischem Routing.
Zusammenfassend sieht die Abfolge der Schritte so aus:
Reservieren Sie unter Google Cloud Console > VPC-Netzwerke > Externe IP-Adressen eine statische IP-Adresse für das Cloud-VPN.
In der AWS VPC-Konsole:
Erstellen Sie ein Kunden-Gateway.
Erstellen Sie ein neues virtuelles privates Gateway oder fügen Sie der VPC, die mit Ihrer Datenbank verknüpft ist, ein vorhandenes hinzu.
Fügen Sie unter Routingtabellen die Weitergabe von Routen hinzu:
Klicken Sie auf Bearbeiten, setzen Sie ein Häkchen in das Kästchen propagate (Verteilen) und klicken Sie auf Speichern, um den IP-Adressbereich Ihres Google Cloud VPC-Netzwerks als Zielbereich hinzuzufügen.
Erstellen Sie in der AWS VPC-Konsole das VPN:
Wählen Sie unter VPN-Verbindungen die Option Site-to-Site-VPN-Verbindungen aus.
Wählen Sie VPN-Verbindung erstellen aus.
Geben Sie einen Namen für die VPN-Verbindung ein.
Wählen Sie unter Virtuelles privates Gateway das private Gateway aus, das Sie zuvor in diesem Verfahren erstellt oder ausgewählt haben.
Wählen Sie unter Kunden-Gateway das Kunden-Gateway aus, das Sie zuvor in diesem Verfahren erstellt haben.
Wählen Sie unter Routing-Optionen die Option Statisch aus und geben Sie die statische IP-Adresse an, die Sie für das Cloud VPN reserviert haben, als CIDR-Bereich an (fügen Sie /32 hinzu).
Laden Sie die Konfiguration herunter, um die Einstellungen zu speichern.
Speichern Sie die Datei als Standard.
Suchen Sie die Abschnitte IP‑Sec-Tunnel 1 und 2.
Notieren Sie sich die IKE-Version und den vorinstallierten Schlüssel für jeden Tunnel.
Notieren Sie sich die IP-Adresse für das virtuelle private Gateway für jeden Tunnel.
Notieren Sie sich die IP-Adresse für die Option „Statische Routenkonfiguration“ für jeden Tunnel.
In der Google Cloud Console > Hybridkonnektivität > VPN:
Klicken Sie auf VPN-Verbindung erstellen.
Wählen Sie Ihr VPC-Netzwerk und Ihre Region aus.
Verwenden Sie für das Cloud VPN die statische IP-Adresse, die Sie zuvor in diesem Verfahren reserviert haben.
Verwenden Sie einen Pre-shared key und einen Schlüsseltyp aus der AWS-Konfiguration, die Sie zuvor in diesem Verfahren heruntergeladen haben.
Wählen Sie die Routingoption Routenbasiert aus und fügen Sie zwei Tunnel hinzu. Verwenden Sie für jedes Feld IP-Bereiche des Remote-Netzwerks des Tunnels eine IP-Adresse für die Option Statische Routenkonfiguration aus den Abschnitten IP Sec Tunnel der AWS-Konfigurationsdatei, die Sie zuvor in diesem Verfahren heruntergeladen haben.
Klicken Sie auf Erstellen.IP-Bereich des Remotenetzwerks
In der AWS RDS-Konsole:
Wählen Sie eine Sicherheitsgruppe aus.
Fügen Sie eingehende Firewallregeln hinzu, um alle Protokolle und Ports aus dem Cloud VPN zuzulassen.
Die VPN-Tunnel sollten bald miteinander kommunizieren. Auf der AWS-Seite haben die Tunnel im VPC-Dashboard den Status UP. Rufen Sie auf der GCP-Seite den Traffic zwischen den VPNs in der Cloud Logging-Konsole im Projekt Cloud VPN gateway auf.
Beispiel 2: AWS mit Google Cloud HA VPN mit dynamischen Routen
Wenn Sie VPC-Peering mit einem HA VPN (dynamische Routen) zu AWS herstellen möchten, müssen Sie BGP-Routen in die Cloud SQL-gepeerte VPC exportieren und eine benutzerdefinierte beworbene Route in Cloud Router für die importierte Route der Cloud SQL-gepeerten VPC erstellen. Zu diesem Zeitpunkt bewirbt Cloud Router AWS-Routen zum Cloud SQL-VPC und umgekehrt. Die Firewallregeln auf beiden Seiten müssen außerdem mit dem CIDR-Wert der Cloud SQL-Peering-Route übereinstimmen.
Auf der AWS-Seite können Sie die ersten drei Schritte in Beispiel 1 ausführen. Wählen Sie jedoch unter Routingoptionen die Option Dynamisch anstelle von Statisch aus.
Bearbeiten Sie dieses VPC-Peering, setzen Sie in den VPC-Peering-Verbindungsdetails ein Häkchen bei Import Custom Routes und Export Custom Routes und klicken Sie auf SPEICHERN.
Das Peering empfängt jetzt dynamische Routen von Ihrem VPC, genau wie die Routen von BGP-Peers. Dadurch wird Traffic vom VPN zum Peering-Netzwerk zugelassen.
Cloud Router bietet diese Route jedoch noch nicht für andere Netzwerke an.
Dazu müssen Sie benutzerdefinierte beworbene Routen im Cloud Router hinzufügen, damit Ihr VPC die importierten Routen für andere Netzwerke angibt. Weitere Informationen finden Sie unter Benutzerdefinierte Routen importieren und exportieren.
Fügen Sie den benutzerdefinierten IP-Bereich DESTINATION_IP_RANGE als benutzerdefinierte Route in die beworbenen Routen der Cloud Router-Konfiguration hinzu. BGP-Peering-Netzwerke erhalten jetzt Anzeigen für die importierten Cloud SQL-Netzwerkrouten, DESTINATION_IP_RANGE. Traffic in diesen VPN-verbundenen Netzwerken, der an das Cloud SQL-Peering-VPC gerichtet ist, wird jetzt über den VPN-Tunnel weitergeleitet.
Routen in AWS-Routingtabellen weitergeben lassen Die AWS-Routentabellen für die Subnetze, die Ihre Quelldatenbank enthalten, müssen einen Eintrag für den Bereich DESTINATION_IP_RANGE enthalten, der zum virtuellen privaten Gateway des VPN führt.
Fügen Sie eine Firewallregel für eingehenden Traffic für die Sicherheitsgruppe hinzu, um Traffic für DESTINATION_IP_RANGETCP port 3306 zuzulassen.
Die Verbindung kann jetzt hergestellt werden.
[[["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\u003eConnecting a source database within a VPN to a destination requires a VPN on the destination side, regardless of the VPN product used.\u003c/p\u003e\n"],["\u003cp\u003eThe source database's firewall must allow the entire internal IP range allocated for the private service connection of the VPC network used by the Cloud SQL destination instance.\u003c/p\u003e\n"],["\u003cp\u003eWhen using AWS with Google Cloud Classic VPN, static routing is employed, necessitating the reservation of a static IP address in Google Cloud and the creation of a customer gateway and VPN in AWS.\u003c/p\u003e\n"],["\u003cp\u003eFor AWS with Google Cloud HA VPN using dynamic routes, BGP routes must be exported to the Cloud SQL peered VPC, and a custom advertised route in Cloud Router must be created to facilitate route advertisement between AWS and Cloud SQL.\u003c/p\u003e\n"],["\u003cp\u003eTo establish connectivity in the HA VPN setup, firewall rules on both sides need to match the Cloud SQL peering route CIDR, and AWS route tables must have an entry for the destination IP range that directs traffic through the VPN Virtual Private Gateway.\u003c/p\u003e\n"]]],[],null,["# Configure connectivity using VPNs\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nMySQL \\| [PostgreSQL](/database-migration/docs/postgres/configure-connectivity-vpns \"View this page for the PostgreSQL version of Database Migration Service.\") \\| [PostgreSQL to AlloyDB](/database-migration/docs/postgresql-to-alloydb/configure-connectivity-vpns \"View this page for the PostgreSQL to AlloyDB version of Database Migration Service.\")\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nOverview\n--------\n\nIf your source database is inside a VPN (in AWS, for example, or your\non-premises VPN), you also need to use a VPN on the destination side to connect\nto the source.\n\nThere are many VPN products you can use. The steps to configure VPNs vary from\none product to another, but all of them are fundamentally similar. This section\ncontains examples using AWS and Google Cloud VPNs.\n\nThe source database server's firewall must be configured to allow the entire **internal\nIP range** allocated for the **private service connection** of the\nVPC network that the Cloud SQL destination instance is going to use as the\n**privateNetwork** field of its [**ipConfiguration** settings](/sql/docs/mysql/replication/replication-from-external#setup-replica-instance).\n\nTo find the **internal IP range** in the console:\n\n1. [Go to the VPC networks page](https://console.cloud.google.com/networking/networks/list) in the Google Cloud console.\n\n2. Select the VPC network that you want to use.\n\n3. Select **Private services access** \\\u003e **Allocated IP ranges for services**.\n\n4. Find the **Internal IP range** associated with the connection created by **servicenetworking-googleapis-com**.\n\n| Note: To use Virtual Private Cloud networking, you must enable the [Service Networking API](https://console.cloud.google.com/apis/library/servicenetworking.googleapis.com) for your Google Cloud project.\n\nExample 1: AWS with Google Cloud Classic VPN with static routes\n---------------------------------------------------------------\n\nFind more complete, step-by-step documentation in the following links:\n\n- On the AWS side, set up a [Site to Site VPN](https://docs.aws.amazon.com/vpn/latest/s2svpn/SetUpVPNConnections.html).\n- On the Google Cloud side, create a [Cloud VPN](/vpn/docs/how-to/creating-static-vpns) using static routing.\n\n\u003cbr /\u003e\n\nPut together, the overall sequence of steps looks like the following:\n\n1. In Google Cloud console \\\u003e VPC Networks \\\u003e External IP addresses, reserve a static IP address to use for the Cloud VPN.\n2. In the AWS VPC console:\n 1. Create a customer gateway.\n 2. Create a new virtual private gateway or add an existing one to the VPC associated with your database.\n 3. In **Routes Tables** add **route propagation**:\n 4. Click **Edit** , check the **propagate** checkbox and **Save** to add the IP address range of your Google Cloud VPC network as the destination range.\n3. In the AWS VPC console, create the VPN:\n 1. Under **VPN Connections** , select **Site-to-site VPN Connections**.\n 2. Select **Create VPN Connection**.\n 3. Enter a name for the VPN connection.\n 4. For **Virtual Private Gateway**, select the private gateway that you created or selected earlier in this procedure.\n 5. For **Customer Gateway**, select the customer gateway that you created earlier in this procedure.\n 6. For **Routing Options** , select **Static**, and specify the static IP address you reserved for the Cloud VPN as a CIDR (add /32).\n 7. Download the configuration to save the settings.\n 1. Save the file as **Default**.\n 2. Find the sections **IP Sec Tunnels** #1 and #2.\n 3. Note the IKE version and **Pre-Shared Key** for each tunnel.\n 4. Note the IP address for the **Virtual Private Gateway** for each tunnel.\n 5. Note the IP address for the **Static Route Configuration option** for each tunnel.\n4. In Google Cloud, create a [Classic VPN using static routing](/vpn/docs/how-to/creating-static-vpns).\n 1. In Google Cloud console \\\u003e Hybrid Connectivity \\\u003e VPN:\n 2. Click **Create VPN connection** .\n 1. Select your VPC network and region.\n 2. For the Cloud VPN, use the static IP address you reserved earlier in this procedure.\n 3. Use a `Pre-shared key` and key type from the AWS configuration you downloaded earlier in this procedure.\n 4. Select the **Route based** routing option and add two tunnels; for each tunnel's **Remote network IP range** field, use an IP address for the **Static Route Configuration option** from the `IP Sec Tunnel` sections of the AWS configuration file you downloaded earlier in this procedure.\n 5. Click **Create** .**Remote network IP range**\n\n\u003c!-- --\u003e\n\n5. In the AWS RDS console:\n 1. Select a security group.\n 2. Add inbound firewall rules to allow all protocols and ports from the Cloud VPN.\n\nThe VPN tunnels should begin communicating shortly. On the AWS side, in the\nVPC Dashboard, the tunnel statuses are `UP`. On the GCP\nside, view the traffic between the VPNs in the\n[Cloud Logging](https://console.cloud.google.com/logs) console in the\n`Cloud VPN gateway` project.\n\nExample 2: AWS with Google Cloud HA VPN with dynamic routes\n-----------------------------------------------------------\n\nTo get VPC Peering with an HA VPN (dynamic routes) to AWS, you need to export BGP routes to the Cloud SQL peered VPC, and create a custom advertised route in Cloud Router for the Cloud SQL peered VPC imported route. At that point, Cloud Router is advertising AWS routes to the Cloud SQL VPC and the other way around. The firewall rules on both sides also need to match the Cloud SQL peering route CIDR.\n\nOn the AWS side, you can follow the first three steps in [Example 1](#static-routes),\nexcept select **Dynamic** instead of **Static** under **Routing options**.\n\n1. Select your Cloud SQL VPC Peering configuration in the [Console](https://console.cloud.google.com/networking/peering) and note the **Destination IP ranges** under **IMPORTED ROUTES** . For more information, see [Importing and exporting custom routes](/vpc/docs/vpc-peering#importing-exporting-routes).\n2. Edit this VPC peering and check `Import Custom Routes` and `Export Custom Routes` in the VPC Peering connection details, and click **SAVE** .\n\n The peering now receives dynamic routes from your VPC like the routes\n coming from BGP peers. This allows traffic from the VPN to the peered network.\n However, Cloud Router is not yet advertising this route to other networks.\n To do so, you need to add custom advertised routes in the Cloud Router so\n that your VPC advertises the imported routes to other networks. For more\n information, see [Importing and exporting custom routes](/network-connectivity/docs/router/concepts/advertised-routes#overview-am).\n3. Add your \u003cvar translate=\"no\"\u003eDESTINATION_IP_RANGE\u003c/var\u003e custom IP range as a custom route in the Cloud Router configuration advertised routes. BGP peered networks are now receiving advertisements of the **imported Cloud SQL\n network routes** , \u003cvar translate=\"no\"\u003eDESTINATION_IP_RANGE\u003c/var\u003e. Traffic on those VPN-connected networks bound for the Cloud SQL peered VPC are now routed through the VPN tunnel.\n4. Allow routes to propagate in AWS route tables. Make sure AWS route tables for the subnets that contain your source database contain an entry for the \u003cvar translate=\"no\"\u003eDESTINATION_IP_RANGE\u003c/var\u003e range that routes to the VPN Virtual Private Gateway.\n5. Add a security group firewall inbound rule to allow traffic for \u003cvar translate=\"no\"\u003eDESTINATION_IP_RANGE\u003c/var\u003e `TCP port 3306`. Connectivity can now be established."]]