Detect if a VM is running in Compute Engine

Linux Windows

This document shows you how to use the metadata server or an operating systemtool to detect whether a VM is running in Compute Engine.

Use the metadata server to detect if a VM is running in Compute Engine

Depending on the VM's operating system, use one of the following procedures tosend a request to themetadata server anddetect if a VM is running in Compute Engine:

Linux VM

  1. From the Linux VM, run the following command:

    curl metadata.google.internal -i
  2. Verify thatMetadata-Flavor: Google exists in output similar to thefollowing:

    HTTP/1.1 200 OKMetadata-Flavor: GoogleContent-Type: application/textDate: Tue, 23 Nov 2021 01:27:16 GMTServer: Metadata Server for VMContent-Length: 22X-XSS-Protection: 0X-Frame-Options: SAMEORIGIN0.1/computeMetadata/

    The existence ofMetadata-Flavor: Google in the output indicates that aCompute Engine VM sent the request.

Windows VM

  1. From the Windows VM, run the following command:

    curl metadata.google.internal -i
  2. Verify thatMetadata-Flavor: Google exists in output similar to thefollowing:

    HTTP/1.1 200 OKMetadata-Flavor: GoogleContent-Type: application/textDate: Tue, 23 Nov 2021 20:48:50 GMTServer: Metadata Server for VMContent-Length: 22X-XSS-Protection: 0X-Frame-Options: SAMEORIGIN0.1/computeMetadata/

    The existence ofMetadata-Flavor: Google in the output indicates that aCompute Engine VM sent the request.

Use operating system tools to detect if a VM is running in Compute Engine

Depending on the VM's operating system, use one of the following procedures touse a tool that is specific to the VM's operating system to detect if the VM isrunning in Compute Engine:

Linux VM

  1. From the Linux VM, run the followingdmidecode command:

    sudo dmidecode -s system-product-name | grep "Google Compute Engine"

    Thisdmidecode command directly accesses the System Management BIOSinformation in/proc/mem.

  2. Verify thatGoogle Compute Engine exists in the output.

Windows VM

  1. From the Windows Command Prompt, run theWMI command-line utility:

    wmic.exe computersystem get model,manufacturer
  2. Verify that theSystem Manufacturer isGoogle and theSystem Model isGoogle Compute Engine.

For information about how to programmatically determine whether a Windows VMis running Compute Engine, see the following:

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-15 UTC.