Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Linux
Windows
As VMs na mesma rede de nuvem privada virtual podem acessar umas às outras usando
nomes DNS internos em vez de endereços IP.
Antes de começar
Configure a autenticação, caso ainda não tenha feito isso.
A autenticação é
o processo de verificação da sua identidade para acesso a serviços e APIs do Google Cloud .
Para executar códigos ou amostras de um ambiente de desenvolvimento local, autentique-se no
Compute Engine selecionando uma das seguintes opções:
Select the tab for how you plan to use the samples on this page:
Console
When you use the Google Cloud console to access Google Cloud services and
APIs, you don't need to set up authentication.
gcloud
Instale a CLI do Google Cloud.
Após a instalação,
inicialize a Google Cloud CLI executando o seguinte comando:
Para mais informações, consulte
Autenticar para usar REST
na documentação de autenticação do Google Cloud .
Determinar o nome DNS interno de uma VM
Use o procedimento a seguir para ler o nome DNS interno atribuído a uma instância de VM. É possível conseguir o nome DNS interno consultando a entrada de metadados hostname.
O servidor de metadados retorna o nome do host da VM em um dos formatos a seguir,
que mostra o tipo de nome DNS interno que a VM usa:
DNS por zona: VM_NAME.ZONE.c.PROJECT_ID.internal
DNS global: VM_NAME.c.PROJECT_ID.internal
Na saída:
VM_NAME: o nome da VM
ZONE: é a zona em que a VM está localizada
PROJECT_ID: o projeto que contém a VM.
Acessar VMs por nome DNS interno
Para acessar a VM, use o nome DNS interno no lugar do endereço IP.
O exemplo a seguir usa ping para conectar uma VM que usa
DNS por zona. Esse método funciona desde que você tenha criado uma
regra de firewall que permita o tráfego ICMP de entrada para a
instância.
$ ping VM_NAME.ZONE.c.PROJECT_ID.internal -c 1
PING VM_NAME.ZONE.c.PROJECT_ID.internal (10.240.0.17) 56(84) bytes of data.
64 bytes from VM_NAME.ZONE.c.PROJECT_ID.internal (10.240.0.17): icmp_seq=1 ttl=64 time=0.136 ms
[[["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-08-18 UTC."],[[["\u003cp\u003eVMs within the same Virtual Private Cloud network can communicate using internal DNS names instead of IP addresses.\u003c/p\u003e\n"],["\u003cp\u003eTo authenticate for Google Cloud services and APIs, you can use the Google Cloud console, gcloud CLI (requiring installation and initialization), or REST API (also using gcloud CLI credentials).\u003c/p\u003e\n"],["\u003cp\u003eThe internal DNS name of a VM can be obtained by querying the \u003ccode\u003ehostname\u003c/code\u003e metadata, available in zonal or global DNS formats.\u003c/p\u003e\n"],["\u003cp\u003eAccess a VM using its internal DNS name by replacing the IP address, ensuring a firewall rule allows incoming traffic.\u003c/p\u003e\n"],["\u003cp\u003eThe format of the internal DNS name are, for zonal: VM_NAME.ZONE.c.PROJECT_ID.internal and for global: VM_NAME.c.PROJECT_ID.internal.\u003c/p\u003e\n"]]],[],null,["# Access VMs using internal DNS\n\nLinux Windows\n\n*** ** * ** ***\n\nVMs in the same Virtual Private Cloud network can access each other by using\ninternal DNS names instead of IP addresses.\n\nBefore you begin\n----------------\n\n- If you haven't already, set up [authentication](/compute/docs/authentication). Authentication verifies your identity for access to Google Cloud services and APIs. To run code or samples from a local development environment, you can authenticate to Compute Engine by selecting one of the following options:\n\n Select the tab for how you plan to use the samples on this page: \n\n ### Console\n\n\n When you use the Google Cloud console to access Google Cloud services and\n APIs, you don't need to set up authentication.\n\n ### gcloud\n\n 1.\n [Install](/sdk/docs/install) the Google Cloud CLI.\n\n After installation,\n [initialize](/sdk/docs/initializing) the Google Cloud CLI by running the following command:\n\n ```bash\n gcloud init\n ```\n\n\n If you're using an external identity provider (IdP), you must first\n [sign in to the gcloud CLI with your federated identity](/iam/docs/workforce-log-in-gcloud).\n | **Note:** If you installed the gcloud CLI previously, make sure you have the latest version by running `gcloud components update`.\n 2. [Set a default region and zone](/compute/docs/gcloud-compute#set_default_zone_and_region_in_your_local_client).\n\n ### REST\n\n\n To use the REST API samples on this page in a local development environment, you use the\n credentials you provide to the gcloud CLI.\n 1. [Install](/sdk/docs/install) the Google Cloud CLI. After installation, [initialize](/sdk/docs/initializing) the Google Cloud CLI by running the following command: \n\n ```bash\n gcloud init\n ```\n 2. If you're using an external identity provider (IdP), you must first [sign in to the gcloud CLI with your federated identity](/iam/docs/workforce-log-in-gcloud).\n\n\n For more information, see\n [Authenticate for using REST](/docs/authentication/rest)\n in the Google Cloud authentication documentation.\n\nDetermine the internal DNS name for a VM\n----------------------------------------\n\nUse the following procedure to read the internal DNS name assigned to a VM\ninstance. You can get the internal DNS name by querying the `hostname` metadata\nentry.\n\n1. [Connect to the VM](/compute/docs/instances/connecting-to-instance).\n2. Query the `hostname` metadata:\n\n ### Linux VMs\n\n ```\n curl \"http://metadata.google.internal/computeMetadata/v1/instance/hostname\" \\\n -H \"Metadata-Flavor: Google\"\n ```\n\n ### Windows VMs\n\n ```\n Invoke-RestMethod `\n -Headers @{\"Metadata-Flavor\" = \"Google\"} `\n -Uri \"http://metadata.google.internal/computeMetadata/v1/instance/hostname\"\n ```\n\nThe metadata server returns the VM's hostname in one of the following formats,\nwhich shows the type of internal DNS name that the VM uses:\n\n- **Zonal DNS** : \u003cvar translate=\"no\"\u003eVM_NAME\u003c/var\u003e.\u003cvar translate=\"no\"\u003eZONE\u003c/var\u003e.`c`.\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e.`internal`\n- **Global DNS** : \u003cvar translate=\"no\"\u003eVM_NAME\u003c/var\u003e.`c`.\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e.`internal`\n\nIn the output:\n\n- \u003cvar translate=\"no\"\u003eVM_NAME\u003c/var\u003e: the name of the VM\n- \u003cvar translate=\"no\"\u003eZONE\u003c/var\u003e: the zone where the VM is located\n- \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: the project to which the VM belongs\n\nAccess VMs by internal DNS name\n-------------------------------\n\nTo access the VM, use the internal DNS name in place of the IP address.\n\nThe following example uses `ping` to contact a VM that uses\n[zonal DNS](/compute/docs/networking/zonal-dns). This method works, provided\nthat you have created a [firewall rule](/vpc/docs/firewalls) that allows\nincoming ICMP traffic to the instance. \n\n```\n$ ping VM_NAME.ZONE.c.PROJECT_ID.internal -c 1\n\nPING \u003cvar translate=\"no\"\u003eVM_NAME\u003c/var\u003e.\u003cvar translate=\"no\"\u003eZONE\u003c/var\u003e.c.\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e.internal (10.240.0.17) 56(84) bytes of data.\n64 bytes from \u003cvar translate=\"no\"\u003eVM_NAME\u003c/var\u003e.\u003cvar translate=\"no\"\u003eZONE\u003c/var\u003e.c.\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e.internal (10.240.0.17): icmp_seq=1 ttl=64 time=0.136 ms\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eVM_NAME\u003c/var\u003e: the name of the VM\n- \u003cvar translate=\"no\"\u003eZONE\u003c/var\u003e: the zone where the VM is located\n- \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: the project to which the VM belongs\n\nWhat's next\n-----------\n\n- Migrate to [zonal DNS](/compute/docs/networking/zonal-dns)\n- Learn more about [internal DNS names for Compute Engine](/compute/docs/internal-dns).\n- [Configure static IP addresses for your VM](/compute/docs/ip-addresses/configure-static-external-ip-address)."]]