Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Linux
Windows
VM dalam jaringan Virtual Private Cloud yang sama dapat saling mengakses menggunakan nama DNS internal, bukan alamat IP.
Sebelum memulai
Jika Anda belum melakukannya, siapkan autentikasi.
Autentikasi adalah
proses yang digunakan untuk memverifikasi identitas Anda untuk mengakses Google Cloud layanan dan API.
Untuk menjalankan kode atau sampel dari lingkungan pengembangan lokal, Anda dapat melakukan autentikasi ke
Compute Engine dengan memilih salah satu opsi berikut:
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
Menginstal Google Cloud CLI.
Setelah penginstalan,
lakukan inisialisasi Google Cloud CLI dengan menjalankan perintah berikut:
Gunakan prosedur berikut untuk membaca nama DNS internal yang ditetapkan ke instance VM. Anda bisa mendapatkan nama DNS internal dengan membuat kueri entri metadata
hostname.
Server metadata menampilkan nama host VM dalam salah satu format berikut, yang menunjukkan jenis nama DNS internal yang digunakan VM:
DNS Zona: VM_NAME.ZONE.c.PROJECT_ID.internal
DNS Global: VM_NAME.c.PROJECT_ID.internal
Pada output:
VM_NAME: nama VM
ZONE: zona tempat VM berada
PROJECT_ID: project tempat VM berada
Mengakses VM dengan nama DNS internal
Untuk mengakses VM, gunakan nama DNS internal, bukan alamat IP.
Contoh berikut menggunakan ping untuk menghubungi VM yang menggunakan DNS zona. Metode ini berfungsi, asalkan Anda telah membuat aturan firewall yang mengizinkan traffic ICMP yang masuk ke instance.
$ 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
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 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,["Linux 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- 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 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\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\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- 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)."]]