Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Linux
Windows
VMs im selben Virtual Private Cloud-Netzwerk können mithilfe interner DNS-Namen anstelle von IP-Adressen aufeinander zugreifen.
Hinweise
Richten Sie die Authentifizierung ein, falls Sie dies noch nicht getan haben.
Bei der Authentifizierung wird Ihre Identität für den Zugriff auf Google Cloud -Dienste und APIs überprüft.
Zum Ausführen von Code oder Beispielen aus einer lokalen Entwicklungsumgebung können Sie sich so bei der Compute Engine authentifizieren:
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
Installieren Sie die Google Cloud CLI.
Initialisieren Sie die Google Cloud CLI nach der Installation mit dem folgenden Befehl:
Wenn Sie die REST API-Beispiele auf dieser Seite in einer lokalen Entwicklungsumgebung verwenden möchten, verwenden Sie die Anmeldedaten, die Sie der gcloud CLI bereitstellen.
Installieren Sie die Google Cloud CLI.
Initialisieren Sie die Google Cloud CLI nach der Installation mit dem folgenden Befehl:
Mit dem folgenden Verfahren können Sie den einer VM zugewiesenen internen DNS-Namen lesen. Sie können den internen DNS-Namen abrufen, indem Sie den Metadateneintrag hostname abfragen.
Der Metadatenserver gibt den Hostnamen der VM in einem der folgenden Formate zurück. Dabei wird der Typ des internen DNS-Namens angezeigt, der von der VM verwendet wird:
Zonal DNS: VM_NAME.ZONE.c.PROJECT_ID.internal
Global DNS: VM_NAME.c.PROJECT_ID.internal
Dabei gilt:
VM_NAME: der Name der VM
ZONE: die Zone, in der sich die VM befindet
PROJECT_ID: das Projekt, zu dem die Instanz gehört.
Mit dem internen DNS-Namen auf VMs zugreifen
Verwenden Sie für den Zugriff auf die VM den internen DNS-Namen anstelle der IP-Adresse.
Im folgenden Beispiel wird mit ping eine VM kontaktiert, die ein zonales DNS verwendet. Diese Methode funktioniert nur, wenn Sie eine Firewallregel erstellt haben, die eingehenden ICMP-Traffic an die Instanz zulässt.
$ 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
Ersetzen Sie Folgendes:
VM_NAME: der Name der VM
ZONE: die Zone, in der sich die VM befindet
PROJECT_ID: das Projekt, zu dem die Instanz gehört.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 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)."]]