Use o Cloud Router
para configurar rotas divulgadas personalizadas entre duas redes que passam por uma
VPC intermediária para conectar várias VPCs à instância do Cloud SQL.
As duas VPCs precisam estar conectadas usando uma
rede privada virtual (VPN), o Cloud Interconnect ou qualquer outra
rede compatível com o
Cloud Router.
Com rotas divulgadas personalizadas, a VPC do Cloud SQL, VPC C,
conecta-se à VPC principal, VPC A, usando uma VPC intermediária, VPC B.
É possível configurar rotas compartilhadas entre essas redes das seguintes maneiras:
É possível usar o Cloud Router para anunciar manualmente rotas entre duas
redes que passam por uma VPC intermediária. Para mais informações sobre como configurar o Cloud Router para anunciar rotas manualmente, consulte Rede de transporte público.
Recomendamos o uso de rotas divulgadas personalizadas para conectar várias VPCs
à instância do Cloud SQL usando o
Cloud Router.
Conectar usando um proxy intermediário (SOCKS5)
É possível configurar um proxy intermediário, como SOCKS5,
em uma VPC intermediária com o proxy de autenticação do Cloud SQL
na VPC principal entre o cliente e a instância do Cloud SQL. Isso
permite que o nó intermediário encaminhe o tráfego criptografado do
proxy de autenticação do Cloud SQL para a instância do Cloud SQL.
Se quiser usar um proxy intermediário para se conectar à instância do Cloud SQL por várias VPCs, siga estas etapas:
Na VM intermediária, instale, configure e execute um servidor SOCKS. Um
exemplo desse servidor é o Dante, uma
solução de código aberto conhecida.
Configure o servidor para se vincular à interface de rede ens4 da VM
para conexões externas e internas. Para conexões internas, especifique qualquer
porta.
Configure o firewall da VPC para permitir
o tráfego TCP do intervalo ou do endereço IP apropriado até a porta configurada do servidor SOCKS.
Como você configurou a instância para usar um endereço IP interno, ao iniciar o proxy do Cloud SQL Auth, forneça a opção --private-ip.
Além disso, defina a variável de ambiente ALL_PROXY como o endereço IP da VM intermediária e especifique a porta que o servidor SOCKS usa. Por exemplo, ALL_PROXY=socks5://VM_IP_ADDRESS:SOCKS_SERVER_PORT.
Se você estiver se conectando a partir de uma
VPC com peering, use o endereço IP interno da VM intermediária.
Caso contrário, use o endereço IP externo.
Conectar usando o Cloud SQL Auth Proxy como serviço
É possível instalar e executar o proxy do Cloud SQL Auth na VPC intermediária em vez
do cliente externo e ativar conexões seguras pareando-o com um
proxy compatível com protocolos, também conhecido como pool de conexões. Exemplos de pools de conexões incluem
PGbouncer ou Pgpool-II(somente PostgreSQL).
Esse método de conexão permite que seus aplicativos se conectem diretamente ao pooler com segurança usando um SSL configurado. O pooler transmite consultas de bancos de dados para a instância do Cloud SQL
usando o proxy de autenticação do Cloud SQL.
Conectar usando o Private Service Connect
O Private Service Connect
permite que você se conecte a várias redes VPC em diferentes projetos
ou organizações. É possível usar o Private Service Connect para se conectar a uma instância primária ou a qualquer uma das réplicas de leitura dela. Para mais
informações sobre o Private Service Connect, consulte
Informações gerais do Private Service Connect.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-09-04 UTC."],[],[],null,["# Connect your instance to multiple VPCs\n\n\u003cbr /\u003e\n\n[MySQL](/sql/docs/mysql/connect-multiple-vpcs \"View this page for the MySQL database engine\") \\| [PostgreSQL](/sql/docs/postgres/connect-multiple-vpcs \"View this page for the PostgreSQL database engine\") \\| SQL Server\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/sqlserver/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/sqlserver/sql-proxy#install).\n\n6. On your external client, [start the Cloud SQL Auth Proxy](/sql/docs/sqlserver/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 a [SQL Server client](/sql/docs/sqlserver/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/sqlserver/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/sqlserver/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/sqlserver/configure-private-service-connect)."]]