Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Linux
Windows
Las VMs de la misma red de nube privada virtual pueden acceder entre sí mediante nombres de DNS internos en lugar de direcciones IP.
Antes de comenzar
Si aún no lo hiciste, configura la autenticación.
La autenticación verifica tu identidad para acceder a los Google Cloud servicios y las APIs. Para ejecutar código o muestras desde un entorno de desarrollo local, puedes autenticarte en Compute Engine seleccionando una de las siguientes opciones:
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
Instala Google Cloud CLI.
Después de la instalación,
inicializa Google Cloud CLI ejecutando el siguiente comando:
Para obtener más información, consulta
Autentícate para usar REST
en la documentación de autenticación de Google Cloud .
Determina el nombre DNS interno para una VM
Usa el siguiente procedimiento para leer el nombre DNS interno asignado a una instancia de VM. Puedes obtener el nombre de DNS interno consultando la entrada de metadatos hostname.
El servidor de metadatos muestra el nombre de host de la VM en uno de los siguientes formatos, que indica el tipo de nombre DNS interno que usa la VM:
DNS zonal: VM_NAME.ZONE.c.PROJECT_ID.internal
DNS Global: VM_NAME.c.PROJECT_ID.internal
En el resultado verás lo siguiente:
VM_NAME: El nombre de la VM
ZONE: La zona donde se ubica la VM.
PROJECT_ID: el proyecto al que pertenece la VM
Accede a las VMs por nombre de DNS interno
Para acceder a la VM, usa el nombre de DNS interno en lugar de la dirección IP.
En el siguiente ejemplo, se usa ping para comunicarse con una VM que utiliza DNS zonal. Este método funciona, siempre y cuando crees una regla de firewall que permita el tráfico de ICMP entrante a la instancia.
$ 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 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)"],[[["\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)."]]