このドキュメントでは、メタデータ サーバーまたはオペレーティング システム ツールを使用して、Compute Engine で VM が実行されているかどうかを検出する方法について説明します。
メタデータ サーバーを使用して Compute Engine での VM の実行を検出する
VM のオペレーティング システムに応じて、次のいずれかの手順でメタデータ サーバーにリクエストを送信し、Compute Engine で VM が実行されているかどうかを検出します。
Linux VM
Linux VM から、次のコマンドを実行します。
curl metadata.google.internal -i
次のように、出力に Metadata-Flavor: Google が含まれているかどうか確認します。
HTTP/1.1 200 OK
Metadata-Flavor: Google
Content-Type: application/text
Date: Tue, 23 Nov 2021 01:27:16 GMT
Server: Metadata Server for VM
Content-Length: 22
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN
0.1/
computeMetadata/
出力に Metadata-Flavor: Google が含まれている場合、Compute Engine VM がリクエストを送信しています。
Windows VM
Windows VM から、次のコマンドを実行します。
curl metadata.google.internal -i
次のように、出力に Metadata-Flavor: Google が含まれているかどうか確認します。
HTTP/1.1 200 OK
Metadata-Flavor: Google
Content-Type: application/text
Date: Tue, 23 Nov 2021 20:48:50 GMT
Server: Metadata Server for VM
Content-Length: 22
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN
0.1/
computeMetadata/
出力に Metadata-Flavor: Google が含まれている場合、Compute Engine VM がリクエストを送信しています。
オペレーティング システム ツールを使用して Compute Engine での VM の実行を検出する
VM のオペレーティング システムに応じて、次のいずれかの手順で VM のオペレーティング システムに固有のツールを使用して、Compute Engine で VM が実行されているかどうかを検出します。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-09-03 UTC。"],[[["\u003cp\u003eThis guide provides methods to determine if a virtual machine (VM) is running within Google Compute Engine.\u003c/p\u003e\n"],["\u003cp\u003eYou can use the metadata server by sending a request via the \u003ccode\u003ecurl\u003c/code\u003e command on both Linux and Windows VMs and checking for the \u003ccode\u003eMetadata-Flavor: Google\u003c/code\u003e header in the output.\u003c/p\u003e\n"],["\u003cp\u003eLinux VMs can utilize the \u003ccode\u003edmidecode\u003c/code\u003e command to confirm the presence of "Google Compute Engine" in the system product name.\u003c/p\u003e\n"],["\u003cp\u003eWindows VMs can use the \u003ccode\u003ewmic.exe\u003c/code\u003e command to verify that the System Manufacturer is "Google" and the System Model is "Google Compute Engine".\u003c/p\u003e\n"]]],[],null,["Linux Windows\n\n*** ** * ** ***\n\nThis document shows you how to use the metadata server or an operating system\ntool to detect whether a VM is running in Compute Engine.\n\nUse the metadata server to detect if a VM is running in Compute Engine\n\nDepending on the VM's operating system, use one of the following procedures to\nsend a request to the [metadata server](/compute/docs/metadata/overview) and\ndetect if a VM is running in Compute Engine: \n\nLinux VM\n\n1. From the Linux VM, run the following command:\n\n ```\n curl metadata.google.internal -i\n ```\n2. Verify that `Metadata-Flavor: Google` exists in output similar to the\n following:\n\n HTTP/1.1 200 OK\n Metadata-Flavor: Google\n Content-Type: application/text\n Date: Tue, 23 Nov 2021 01:27:16 GMT\n Server: Metadata Server for VM\n Content-Length: 22\n X-XSS-Protection: 0\n X-Frame-Options: SAMEORIGIN\n\n 0.1/\n computeMetadata/\n\n The existence of `Metadata-Flavor: Google` in the output indicates that a\n Compute Engine VM sent the request.\n\nWindows VM\n\n1. From the Windows VM, run the following command:\n\n ```\n curl metadata.google.internal -i\n ```\n2. Verify that `Metadata-Flavor: Google` exists in output similar to the\n following:\n\n HTTP/1.1 200 OK\n Metadata-Flavor: Google\n Content-Type: application/text\n Date: Tue, 23 Nov 2021 20:48:50 GMT\n Server: Metadata Server for VM\n Content-Length: 22\n X-XSS-Protection: 0\n X-Frame-Options: SAMEORIGIN\n\n 0.1/\n computeMetadata/\n\n The existence of `Metadata-Flavor: Google` in the output indicates that a\n Compute Engine VM sent the request.\n\nUse operating system tools to detect if a VM is running in Compute Engine\n\nDepending on the VM's operating system, use one of the following procedures to\nuse a tool that is specific to the VM's operating system to detect if the VM is\nrunning in Compute Engine: \n\nLinux VM\n\n1. From the Linux VM, run the following\n [`dmidecode`](http://www.nongnu.org/dmidecode/)\n command:\n\n ```\n sudo dmidecode -s system-product-name | grep \"Google Compute Engine\"\n ```\n\n This `dmidecode` command directly accesses the System Management BIOS\n information in `/proc/mem`.\n2. Verify that `Google Compute Engine` exists in the output.\n\nWindows VM\n\n1. From the Windows Command Prompt, run the [WMI command-line utility](https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmic):\n\n ```\n wmic.exe computersystem get model,manufacturer\n ```\n2. Verify that the `System Manufacturer` is `Google` and the `System Model` is\n `Google Compute Engine`.\n\nFor information about how to programmatically determine whether a Windows VM\nis running Compute Engine, see the following:\n\n- [Create a WMI application using C++](http://msdn.microsoft.com/library/windows/desktop/aa389762%28v=vs.85%29.aspx)\n- [Getting manufacturer and model from the Windows registry in C++](http://stackoverflow.com/questions/12300442/how-to-get-computer-manufacturer-and-model-from-windows-registry-in-c)"]]