Detect if a VM is running in Compute Engine
This document shows you how to use the metadata server or an operating system
tool to detect whether a VM is running in Compute Engine.
Depending on the VM's operating system, use one of the following procedures to
send a request to the metadata server and
detect if a VM is running in Compute Engine:
Linux VM
From the Linux VM, run the following command:
curl metadata.google.internal -i
Verify that Metadata-Flavor: Google
exists in output similar to the
following:
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/
The existence of Metadata-Flavor: Google
in the output indicates that a
Compute Engine VM sent the request.
Windows VM
From the Windows VM, run the following command:
curl metadata.google.internal -i
Verify that Metadata-Flavor: Google
exists in output similar to the
following:
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/
The existence of Metadata-Flavor: Google
in the output indicates that a
Compute Engine VM sent the request.
Depending on the VM's operating system, use one of the following procedures to
use a tool that is specific to the VM's operating system to detect if the VM is
running in Compute Engine:
Linux VM
From the Linux VM, run the following
dmidecode
command:
sudo dmidecode -s system-product-name | grep "Google Compute Engine"
This dmidecode
command directly accesses the System Management BIOS
information in /proc/mem
.
Verify that Google Compute Engine
exists in the output.
Windows VM
From the Windows Command Prompt, run the WMI command-line utility:
wmic.exe computersystem get model,manufacturer
Verify that the System Manufacturer
is Google
and the System Model
is
Google Compute Engine
.
For information about how to programmatically determine whether a Windows VM
is running Compute Engine, see the following:
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-26 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-26 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,["# Detect if a VM is running in Compute Engine\n\nLinux 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----------------------------------------------------------------------\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\n### Linux 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\n### Windows 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-------------------------------------------------------------------------\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\n### Linux 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\n### Windows 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)"]]