Access VMs using internal DNS

Linux Windows

VMs in the same Virtual Private Cloud network can access each other by usinginternal DNS names instead of IP addresses.

Before you begin

Determine the internal DNS name for a VM

Use the following procedure to read the internal DNS name assigned to a VMinstance. You can get the internal DNS name by querying thehostname metadataentry.

  1. Connect to the VM.
  2. Query thehostname metadata:

    Linux VMs

    curl "http://metadata.google.internal/computeMetadata/v1/instance/hostname" \  -H "Metadata-Flavor: Google"

    Windows VMs

    Invoke-RestMethod `  -Headers @{"Metadata-Flavor" = "Google"} `  -Uri "http://metadata.google.internal/computeMetadata/v1/instance/hostname"

The metadata server returns the VM's hostname in one of the following formats,which shows the type of internal DNS name that the VM uses:

  • Zonal DNS:VM_NAME.ZONE.c.PROJECT_ID.internal
  • Global DNS:VM_NAME.c.PROJECT_ID.internal

In the output:

  • VM_NAME: the name of the VM
  • ZONE: the zone where the VM is located
  • PROJECT_ID: the project to which the VM belongs

Access VMs by internal DNS name

To access the VM, use the internal DNS name in place of the IP address.

The following example usesping to contact a VM that useszonal DNS. This method works, providedthat you have created afirewall rule that allowsincoming ICMP traffic to the instance.

$pingVM_NAME.ZONE.c.PROJECT_ID.internal -c 1PINGVM_NAME.ZONE.c.PROJECT_ID.internal (10.240.0.17) 56(84) bytes of data.64 bytes fromVM_NAME.ZONE.c.PROJECT_ID.internal (10.240.0.17): icmp_seq=1 ttl=64 time=0.136 ms

Replace the following:

  • VM_NAME: the name of the VM
  • ZONE: the zone where the VM is located
  • PROJECT_ID: the project to which the VM belongs

What's next

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-15 UTC.