Detectar se uma VM está em execução no Compute Engine
Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Linux
Windows
Neste documento, você aprenderá a usar o servidor de metadados ou uma ferramenta de sistema operacional para detectar se uma VM está em execução no Compute Engine.
Usar o servidor de metadados para detectar se uma VM está em execução no Compute Engine
Dependendo do sistema operacional da VM, use um dos procedimentos a seguir para enviar uma solicitação ao servidor de metadados e detectar se uma VM está em execução no Compute Engine:
VM do Linux
Na VM do Linux, execute o seguinte comando:
curl metadata.google.internal -i
Verifique se Metadata-Flavor: Google existe em uma saída semelhante à seguinte:
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/
A existência de Metadata-Flavor: Google na saída indica que uma VM do Compute Engine enviou a solicitação.
VM do Windows
Na VM do Windows, execute o seguinte comando:
curl metadata.google.internal -i
Verifique se Metadata-Flavor: Google existe em uma saída semelhante à seguinte:
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/
A existência de Metadata-Flavor: Google na saída indica que uma VM do Compute Engine enviou a solicitação.
Usar ferramentas do sistema operacional para detectar se uma VM está em execução no Compute Engine
Dependendo do sistema operacional da VM, use um dos procedimentos a seguir para usar uma ferramenta específica do sistema operacional da VM para detectar se ela está em execução no Compute Engine:
VM do Linux
Na VM do Linux, execute o seguinte comando
dmidecode:
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-05-15 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)"]]