Rileva se una VM è in esecuzione in Compute Engine
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Linux
Windows
Questo documento mostra come utilizzare il server di metadati o uno strumento del sistema operativo per rilevare se una VM è in esecuzione in Compute Engine.
Utilizza il server di metadati per rilevare se una VM è in esecuzione in Compute Engine
A seconda del sistema operativo della VM, utilizza una delle seguenti procedure per inviare una richiesta al server di metadati e rilevare se una VM è in esecuzione in Compute Engine:
VM Linux
Dalla VM Linux, esegui questo comando:
curl metadata.google.internal -i
Verifica che Metadata-Flavor: Google esista in un output simile al seguente:
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/
La presenza di Metadata-Flavor: Google nell'output indica che una VM di Compute Engine ha inviato la richiesta.
VM Windows
Dalla VM Windows, esegui questo comando:
curl metadata.google.internal -i
Verifica che Metadata-Flavor: Google esista in un output simile al seguente:
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/
La presenza di Metadata-Flavor: Google nell'output indica che una VM di Compute Engine ha inviato la richiesta.
Utilizza gli strumenti del sistema operativo per rilevare se una VM è in esecuzione in Compute Engine
A seconda del sistema operativo della VM, utilizza una delle seguenti procedure per utilizzare uno strumento specifico per il sistema operativo della VM per rilevare se la VM è in esecuzione in Compute Engine:
VM Linux
Dalla VM Linux, esegui il seguente comando dmidecode:
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-08-04 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)"]]