Se il database di origine si trova all'interno di una VPN (ad esempio in AWS o nella tua VPN on-premise), devi utilizzare una VPN anche sul lato di destinazione per connetterti all'origine.
Esistono molti prodotti VPN che puoi utilizzare. I passaggi per configurare le VPN variano da un prodotto all'altro, ma sono tutti fondamentalmente simili. Questa sezione contiene esempi che utilizzano AWS e VPN. Google Cloud
Google Cloud Inoltre, crea una VPN Cloud utilizzando il routing statico.
Nel complesso, la sequenza generale dei passaggi è la seguente:
In Google Cloud console > Reti VPC > Indirizzi IP esterni, prenota un indirizzo IP statico da utilizzare per la Cloud VPN.
Nella console VPC AWS:
Crea un gateway per i clienti.
Crea un nuovo gateway privato virtuale o aggiungine uno esistente al VPC associato al tuo database.
In Route Tables (Tabelle route), aggiungi la propagazione dei route:
Fai clic su Modifica, seleziona la casella di controllo Propaga e fai clic su Salva per aggiungere l'intervallo di indirizzi IP della tua Google Cloud rete VPC come intervallo di destinazione.
Nella console VPC AWS, crea la VPN:
In Connessioni VPN, seleziona Connessioni VPN site-to-site.
Seleziona Crea connessione VPN.
Inserisci un nome per la connessione VPN.
Per Virtual Private Gateway (Gateway privato virtuale), seleziona il gateway privato che hai creato o selezionato in precedenza in questa procedura.
Per Customer Gateway (Gateway cliente), seleziona il gateway cliente che hai creato
in precedenza in questa procedura.
Per Opzioni di routing, seleziona Statico e specifica l'indirizzo IP statico che hai prenotato per la Cloud VPN come CIDR (aggiungi /32).
Scarica la configurazione per salvare le impostazioni.
Salva il file come Predefinito.
Individua le sezioni IP Sec Tunnels 1 e 2.
Prendi nota della versione IKE e della chiave precondivisa per ogni tunnel.
Prendi nota dell'indirizzo IP del Virtual Private Gateway per ogni tunnel.
Prendi nota dell'indirizzo IP per l'opzione di configurazione della route statica per ogni tunnel.
In Google Cloud console > Connettività ibrida > VPN:
Fai clic su Crea connessione VPN.
Seleziona la rete VPC e la regione.
Per Cloud VPN, utilizza l'indirizzo IP statico che hai prenotato in precedenza
in questa procedura.
Utilizza un Pre-shared key e un tipo di chiave dalla configurazione AWS scaricata in precedenza in questa procedura.
Seleziona l'opzione di routing In base alla route e aggiungi due tunnel. Per ogni campo Intervallo IP rete remota del tunnel, utilizza un indirizzo IP per l'opzione di configurazione della route statica dalle sezioni IP Sec Tunnel del file di configurazione AWS scaricato in precedenza in questa procedura.
Fai clic su Crea.Intervallo IP della rete remota
Nella console AWS RDS:
Seleziona un gruppo di sicurezza.
Aggiungi regole firewall in entrata per consentire tutti i protocolli e le porte della Cloud VPN.
I tunnel VPN dovrebbero iniziare a comunicare a breve. Sul lato AWS, nella dashboard VPC, gli stati dei tunnel sono UP. Sul lato Google Cloud, visualizza il traffico tra le VPN nella console Cloud Logging del progetto Cloud VPN gateway.
Esempio 2: AWS con VPN ad alta disponibilità Google Cloud con route dinamici
Per ottenere il peering VPC con una VPN ad alta disponibilità (route dinamiche) con AWS, devi esportare le route BGP nella VPC in peering con AlloyDB e creare una route pubblicizzata personalizzata nel router Cloud per la route importata della VPC in peering con AlloyDB. A quel punto, il router Cloud annuncia le route AWS al VPC AlloyDB e viceversa. Inoltre, le regole firewall su entrambi i lati devono corrispondere al CIDR della route di peering AlloyDB.
Sul lato AWS, puoi seguire i primi tre passaggi dell'esempio 1,
ma in Opzioni di routing seleziona Dinamico anziché Statico.
Seleziona la configurazione del peering VPC di AlloyDB nella console
e prendi nota degli intervalli IP di destinazione in ROUTE IMPORTATE.
Per ulteriori informazioni, consulta Importare ed esportare route personalizzate.
Modifica questo peering VPC e seleziona Import Custom Routes e
Export Custom Routes nei dettagli della connessione del peering VPC,
poi fai clic su SALVA.
Il peering ora riceve route dinamiche dalla tua VPC, come le route provenienti dai peer BGP. In questo modo, il traffico dalla VPN alla rete in peering è consentito.
Tuttavia, il router Cloud non sta ancora pubblicizzando questa route ad altre reti.
Per farlo, devi aggiungere route annunciate personalizzate nel router Cloud in modo che il VPC annunci le route importate ad altre reti. Per ulteriori informazioni, consulta Importare ed esportare route personalizzate.
Aggiungi il tuo intervallo IP personalizzato DESTINATION_IP_RANGE come route personalizzato nelle route annunciate nella configurazione del router Cloud. Le reti BGP con peering ora ricevono annunci dei percorsi di rete AlloyDB importati, DESTINATION_IP_RANGE. Il traffico su queste reti collegate tramite VPN destinate alla VPC in peering di AlloyDB ora viene reindirizzato tramite il tunnel VPN.
Consenti la propagazione delle route nelle tabelle di route AWS. Assicurati che le tabelle di route AWS per le subnet che contengono il database di origine contengano una voce per l'intervallo DESTINATION_IP_RANGE che inoltra al gateway privato virtuale VPN.
Aggiungi una regola firewall in entrata del gruppo di sicurezza per consentire il traffico per
DESTINATION_IP_RANGETCP port 5432.
Ora è possibile stabilire la connettività.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-05 UTC."],[[["\u003cp\u003eTo connect a source database within a VPN (like AWS or on-premises) to an AlloyDB destination, a VPN must also be established on the destination side.\u003c/p\u003e\n"],["\u003cp\u003eThe source database server's firewall needs to be configured to allow traffic from the internal IP range designated for the private service connection of the AlloyDB destination's VPC network.\u003c/p\u003e\n"],["\u003cp\u003eSetting up a VPN between AWS and Google Cloud can be achieved using either static routing (Classic VPN) or dynamic routing (HA VPN), each with specific configuration steps on both platforms.\u003c/p\u003e\n"],["\u003cp\u003eWhen using HA VPN with dynamic routes, you must export BGP routes to the AlloyDB peered VPC and create a custom advertised route in Cloud Router for the imported route.\u003c/p\u003e\n"],["\u003cp\u003eWith dynamic routes, ensure that firewall rules on both the AWS and Google cloud sides match the AlloyDB peering route CIDR, and that routes are allowed to propagate in the AWS route tables.\u003c/p\u003e\n"]]],[],null,["# Configure connectivity using VPNs\n\n\u003cbr /\u003e\n\n[MySQL](/database-migration/docs/mysql/configure-connectivity-vpns \"View this page for the MySQL version of Database Migration Service.\") \\| [PostgreSQL](/database-migration/docs/postgres/configure-connectivity-vpns \"View this page for the PostgreSQL version of Database Migration Service.\") \\| PostgreSQL to AlloyDB\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\n[VPC network that the AlloyDB destination instance is going to use](/database-migration/docs/postgresql-to-alloydb/create-migration-job#dest).\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 AlloyDB peered VPC, and create a custom advertised route in Cloud Router for the AlloyDB peered VPC imported route. At that point, Cloud Router is advertising AWS routes to the AlloyDB VPC and the other way around. The firewall rules on both sides also need to match the AlloyDB 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 AlloyDB 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 AlloyDB\n network routes** , \u003cvar translate=\"no\"\u003eDESTINATION_IP_RANGE\u003c/var\u003e. Traffic on those VPN-connected networks bound for the AlloyDB 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 5432`. Connectivity can now be established."]]