Puedes usar Cloud Router
para configurar rutas anunciadas personalizadas entre dos redes que pasan por un
una VPC intermedia para conectar varias a tu instancia de Cloud SQL.
Las dos VPC deben estar conectadas mediante una red privada virtual (VPN), Cloud Interconnect o cualquier otra red compatible con Cloud Router.
Con los anuncios de ruta personalizados, tu VPC de Cloud SQL, VPC C, está conectada a tu VPC principal, VPC A, mediante una VPC intermedia, VPC B.
Puedes configurar rutas compartidas entre estas redes de las siguientes maneras:
Puedes usar Cloud Router para anunciar rutas de forma manual entre dos redes que pasan por una VPC intermedia. Para obtener más información sobre cómo configurar Cloud Router para anunciar rutas de forma manual, consulta Red de tránsito.
Recomendamos usar rutas anunciadas personalizadas para conectar varias VPC
a tu instancia de Cloud SQL con
Cloud Router.
Conéctate con un proxy intermedio (SOCKS5)
Puedes configurar un proxy intermedio, como el proxy SOCKS5, en una VPC intermedia junto con el proxy de autenticación de Cloud SQL en la VPC principal entre el cliente y la instancia de Cloud SQL. Esto permite que el nodo intermedio reenvíe el tráfico encriptado desde el proxy de autenticación de Cloud SQL a la instancia de Cloud SQL.
Si quieres usar un proxy intermediario para conectarte a tu instancia de Cloud SQL desde varias VPC, sigue estos pasos:
En la VM intermediaria, instala, configura y ejecuta un servidor SOCKS. Un
ejemplo de este servidor es Dante, una
solución popular de código abierto.
Configura el servidor a fin de que se vincule a la interfaz de red ens4 de la VM
para conexiones internas y externas. Para conexiones internas, especifica cualquier
puerto.
Configura el firewall de tu VPC para permitir el tráfico de TCP desde la dirección IP o el rango adecuado al puerto configurado del servidor SOCKS.
Debido a que configuraste tu instancia para usar una dirección IP interna, cuando inicias el proxy de autenticación de Cloud SQL, debes proporcionar la opción --private-ip.
Además, configura la variable de entorno ALL_PROXY en la dirección IP de la VM intermediaria y especifica el puerto que usa el servidor SOCKS. Por ejemplo, ALL_PROXY=socks5://VM_IP_ADDRESS:SOCKS_SERVER_PORT.
Si te conectas desde una
VPC de intercambio de tráfico, usa la dirección IP interna de la VM intermediaria.
De lo contrario, usa la dirección IP externa.
En tu cliente externo, prueba tu conexión con mysql.
Conéctate con el proxy como servicio de Cloud SQL Auth
Puedes instalar y ejecutar el proxy de Cloud SQL Auth en tu VPC intermedia en lugar de tu cliente externo y habilitar las conexiones seguras si lo sincronizas con un proxy adaptado al protocolo, también conocido como agrupador de conexiones. Algunos ejemplos de agrupadores de conexiones son PGBouncer o Pgpool-II(solo PostgreSQL).
Este método de conexión permite que las aplicaciones se conecten de forma segura directamente al agrupador mediante un SSL configurado. El agrupador pasa consultas de bases de datos a tu instancia de Cloud SQL con el proxy de Cloud SQL Auth.
Conéctate mediante Private Service Connect
Private Service Connect te permite conectarte a varias redes de VPC en diferentes proyectos u organizaciones. Puedes usar Private Service Connect para conectarte a una instancia principal o a cualquiera de sus réplicas de lectura. Para obtener más información sobre Private Service Connect, consulta Descripción general de Private Service Connect.
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-09-04 (UTC)"],[],[],null,["# Connect your instance to multiple VPCs\n\n\u003cbr /\u003e\n\nMySQL \\| [PostgreSQL](/sql/docs/postgres/connect-multiple-vpcs \"View this page for the PostgreSQL database engine\") \\| [SQL Server](/sql/docs/sqlserver/connect-multiple-vpcs \"View this page for the SQL Server database engine\")\n\n\u003cbr /\u003e\n\nThis page describes how to connect to your Cloud SQL instance across\ntransitively peered VPCs.\n\nCloud SQL offers the following ways to connect your Cloud SQL instance\nto multiple VPCs using private IP:\n\n- [Connect using custom advertised routes](#custom-route)\n- [Connect using an intermediate proxy (SOCKS5)](#intermediate-proxy)\n- [Connect using Proxy as a service](#proxy-service)\n- [Connect using Private Service Connect](#connect-psc)\n\nConnect using custom advertised routes\n--------------------------------------\n\nYou can use [Cloud Router](/network-connectivity/docs/router/concepts/overview)\nto configure custom advertised routes between two networks that go through an\nintermediate VPC to connect multiple VPCs to your Cloud SQL instance.\nThe two VPCs must be connected using a\nvirtual private network (VPN), Cloud Interconnect , or any other\n[Cloud Router](/network-connectivity/docs/router/concepts/overview) supported\nnetwork.\n\nWith custom advertised routes, your Cloud SQL VPC, *VPC C* ,\nis connected to your main VPC, *VPC A* , using an intermediate VPC, *VPC B*.\nYou can configure shared routes between these networks in the following ways:\n\n- You can use Cloud Router to manually advertise routes between two\n networks that go through an intermediate VPC. For more information on\n how to configure Cloud Router to manually advertise routes,\n see [Transit network](/vpc/docs/vpc-peering#transit-network).\n\n- You can create two [HA VPN gateways](/network-connectivity/docs/vpn/concepts/topologies#2-gcp-gateways)\n that connect to each other to bridge the two different VPCs and configure\n Cloud Router to share routes between them. For more information on how to\n set up HA VPN gateways, see\n [Create HA VPN gateways to connect VPC networks](/network-connectivity/docs/vpn/how-to/creating-ha-vpn2#creating-ha-gw-2-gw-and-tunnel).\n\nWe recommend using custom advertised routes to connect multiple VPCs\nto your Cloud SQL instance using\n[Cloud Router](/network-connectivity/docs/router/concepts/overview).\n\nConnect using an intermediate proxy (SOCKS5)\n--------------------------------------------\n\nYou can set up an intermediate proxy, such as SOCKS5 proxy,\non an intermediate VPC along with the [Cloud SQL Auth Proxy](/sql/docs/mysql/proxy)\nin your main VPC between the client and your Cloud SQL instance. This\nenables the intermediate node to forward encrypted traffic from the\nCloud SQL Auth Proxy to the Cloud SQL instance.\n\nTo use an intermediary proxy to connect to your Cloud SQL instance from multiple VPCs, follow these steps:\n\n1. On your external client, [install](/sdk/docs/install)[gcloud CLI](/sdk/gcloud).\n\n2. On the intermediary VM, install, configure, and run a SOCKS server. One\n example of this server is [Dante](https://www.inet.no/dante/), a\n popular open source solution.\n\n3. Configure the server to bind to the VM's `ens4` network interface\n for both external and internal connections. For internal connections, specify any\n port.\n\n4. [Configure your VPC's firewall](/vpc/docs/firewalls) to allow TCP\n traffic from the appropriate IP address or range to\n the SOCKS server's configured port.\n\n5. On your external client, [download and install the Cloud SQL Auth Proxy](/sql/docs/mysql/sql-proxy#install).\n\n6. On your external client, [start the Cloud SQL Auth Proxy](/sql/docs/mysql/connect-auth-proxy#start-proxy).\n\n Because you configured your instance to use an internal IP address, when you start the Cloud SQL Auth Proxy, you must provide the `--private-ip` option.\n\n Also, set the `ALL_PROXY` environment variable to the intermediary VM's IP address and specify the port that the SOCKS server uses. For example, `ALL_PROXY=socks5://`\u003cvar translate=\"no\"\u003eVM_IP_ADDRESS\u003c/var\u003e`:`\u003cvar translate=\"no\"\u003eSOCKS_SERVER_PORT\u003c/var\u003e`.`\n | **Note:** The default port for the SOCKS server is `1080`.\n\n If you're connecting from a\n peered VPC, then use the intermediary VM's internal IP address;\n otherwise, use its external IP address.\n7. On your external client, test your connection using [`mysql`](/sql/docs/mysql/connect-admin-ip).\n\nConnect using the Cloud SQL Auth Proxy as a service\n---------------------------------------------------\n\nYou can install and run the Cloud SQL Auth Proxy on your intermediate VPC instead\nof your external client and enable secure connections by pairing it with a\nprotocol-aware proxy, also known as a connection pooler. Examples of connection poolers include\n[PGbouncer](https://www.pgbouncer.org/), or [Pgpool-II](https://pgpool.net/)(PostgreSQL only).\n\nThis connection method allows your applications to securely connect directly to the pooler\nusing a configured SSL. The pooler passes databases queries to your Cloud SQL instance\nusing the Cloud SQL Auth Proxy.\n| **Note:** You'll need to set up your own secure connection. These connections aren't secured by Cloud SQL.\n\nConnect using Private Service Connect\n-------------------------------------\n\n[Private Service Connect](/sql/docs/mysql/about-private-service-connect)\nallows you to connect to multiple VPC networks across different projects\nor organizations. You can use Private Service Connect to connect\nto either a primary instance or any of its read replicas. For more\ninformation about Private Service Connect, see\n[Private Service Connect overview](/sql/docs/mysql/about-private-service-connect).\n\nTo connect across multiple VPCs using Private Service Connect,\nsee [Connect to an instance using Private Service Connect](/sql/docs/mysql/configure-private-service-connect)."]]