同じ Virtual Private Cloud ネットワーク内にある VM は、IP アドレスではなく内部 DNS 名を使用して相互にアクセスできます。
始める前に
-
まだ設定していない場合は、認証を設定します。認証とは、 Trusted Cloud by S3NS サービスと API にアクセスするために ID を確認するプロセスです。ローカル開発環境からコードまたはサンプルを実行するには、次のいずれかのオプションを選択して Compute Engine に対する認証を行います。
Select the tab for how you plan to use the samples on this page:
Console
When you use the Trusted Cloud console to access Trusted Cloud by S3NS services and APIs, you don't need to set up authentication.
gcloud
-
After installing the Google Cloud CLI, sign in to the gcloud CLI with your federated identity and then initialize it by running the following command:
gcloud init
- Set a default region and zone.
- VM に接続します。
hostname
メタデータに対してクエリを実行します。Linux VM
curl "http://metadata.google.internal/computeMetadata/v1/instance/hostname" \ -H "Metadata-Flavor: Google"
Windows VM
Invoke-RestMethod ` -Headers @{"Metadata-Flavor" = "Google"} ` -Uri "http://metadata.google.internal/computeMetadata/v1/instance/hostname"
- ゾーン DNS:
VM_NAME
.ZONE
.c
.PROJECT_ID
.internal
- グローバル DNS:
VM_NAME
.c
.PROJECT_ID
.internal
VM_NAME
: VM の名前ZONE
: VM を配置するゾーンPROJECT_ID
: VM が属するプロジェクトVM_NAME
: VM の名前ZONE
: VM を配置するゾーンPROJECT_ID
: VM が属するプロジェクト- ゾーン DNS へ移行する。
- Compute Engine の内部 DNS 名の詳細を見る。
- VM の静的 IP アドレスを構成する。
REST
このページの REST API サンプルをローカル開発環境で使用するには、gcloud CLI に指定した認証情報を使用します。
After installing the Google Cloud CLI, sign in to the gcloud CLI with your federated identity and then initialize it by running the following command:
gcloud init
詳細については、 Trusted Cloud 認証ドキュメントの REST を使用して認証するをご覧ください。
VM の内部 DNS 名を確認する
VM インスタンスに割り当てられた内部 DNS 名を読み取るには、次の操作を行います。内部 DNS 名を取得するには、
hostname
メタデータ エントリをクエリします。メタデータ サーバーは、次のいずれかの形式で VM のホスト名を返し、VM が使用する内部 DNS 名のタイプを示します。
出力の中で:
内部 DNS 名で VM にアクセスする
VM にアクセスするには、IP アドレスの代わりに内部 DNS 名を使用します。
次の例では、
ping
を使用して、ゾーン DNS を使用する VM に接続します。この方法は、インスタンスへの受信 ICMP トラフィックを許可するファイアウォール ルールを作成した場合に機能します。$ 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
次のように置き換えます。
次のステップ
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-07-21 UTC。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-07-21 UTC。"],[[["VMs within the same Virtual Private Cloud network can communicate using internal DNS names instead of IP addresses."],["To 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)."],["The internal DNS name of a VM can be obtained by querying the `hostname` metadata, available in zonal or global DNS formats."],["Access a VM using its internal DNS name by replacing the IP address, ensuring a firewall rule allows incoming traffic."],["The 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."]]],[]] -