Rename a VM

Linux Windows

When you create a virtual machine (VM) instance, you must specify a name. Aftercreating the VM, you can optionally rename it. Changing a VM name might beuseful in the following scenarios:

  • To better represent the workload running on the VM.
  • To refer to the operating system running on the VM.
  • To adhere to any naming conventions required by your organization.

VM uniform resource identifiers (URIs)

Changing the name of a VM might affect your projects. Instead of referencing VMresources by their name, you can reference them by their URI, which ispermanent. The URI has the following format:

projects/PROJECT_ID/zones/ZONE/instances/VM_ID

The URI includes the following values:

  • PROJECT_ID: the ID of the project where the VM islocated.

  • ZONE: the zone where the VM is located.

  • VM_ID: the ID of an existing VM. To view the ID of anexisting VM,view the details of the VM andthen view the value of theid field.

Pricing

Renaming a VM does not change the amount that you are billed. Also, because yourbill shows VMs according to their stock keeping units (SKUs) and not theirnames, you won't see the names of your VMs on your bill.

Limitations

Limitations on the following apply when renaming a VM:

  • Automatically named resources:

    • When you rename a VM, the names of any resources that were based on theoriginal VM name are not updated. For example, when you create a VM, thename of the boot disk is the same as the name of the VM. If you rename theVM, the name of the boot disk does not change.
  • DHCP server:

    • After renaming a VM, the DHCP server responds to DHCP requests with theupdated hostname with the formatHOSTNAME.c.PROJECT_ID.internalfor global DNS andHOSTNAME.ZONE.c.PROJECT_ID.internalfor zonal DNS. For more information, seeTypes of internal DNSnames.
  • Google Cloud console:

    • You must refresh your browser for the Google Cloud console to update thename of the VM.
  • Hostnames:

    • Hostnames are modified on Linux when you change the name of the instance. OnWindows, the hostname is not updated, even after you restart the instance.

    • VMs that havecustomhostnames are not updated.

    • Changing the hostname directly on the host does not affect the name of theVM resource.

  • Instance groups:

    • You can't rename instances that are part of an unmanaged or managed instance group (MIG).
  • Naming conventions:

    • You can't rename a VM with a name that is already in use by another VM inthe project.

    • VM names must adhere to theresource namingconventions.

  • VM states:

    • Stop the instance beforerenaming it because you can only rename VMs that are in theTERMINATEDstate. You can't, for example, rename a VM that is in theSUSPENDED state.

Before you begin

Required roles

To get the permission that you need to rename a VM, ask your administrator to grant you theCompute Instance Admin (v1) (roles/compute.instanceAdmin.v1) IAM role on the project. For more information about granting roles, seeManage access to projects, folders, and organizations.

This predefined role contains the compute.instances.setName permission, which is required to rename a VM.

You might also be able to get this permission withcustom roles or otherpredefined roles.

Rename a VM

You can only rename stopped VMs that are in theTERMINATED state.

Console

To rename a VM, do the following:

  1. In the Google Cloud console, go to theVM instances page.

    Go to VM instances

  2. In theName column, click the name of the VM.

  3. If you haven't already, clickStopto stop the VM. If there is noStop option, clickMore actions >Stop.

  4. ClickEdit.

  5. In theVM instance name field, enter a new name for the VM.

  6. ClickSave.

    Renaming the VM can take up to a minute to complete. If, after renamingthe VM, you get an error that Google Cloud is unable to find theVM, refresh your browser.

  7. If you need to, restart the VM by clickingStart / Resume.

gcloud

To rename a VM, do the following:

  1. If you haven't already,stop the VM.

  2. To rename the VM, use thegcloud compute instances set-name command.

    gcloud compute instances set-nameVM_NAME \    --new-name=NEW_VM_NAME \    --project=PROJECT_ID \    --zone=ZONE

    Replace the following:

    • VM_NAME: the name of an existing VM.

    • NEW_VM_NAME: the new name for the specified VM.

    • PROJECT_ID: the ID of the project where the VMis located.

    • ZONE: the zone where the VM is located.

    Renaming the VM can take up to a minute to complete.

  3. If you need to,restart the VM.

REST

To rename a VM, do the following:

  1. If you haven't already,stop the VM.

  2. To rename the VM, make aPOST request to theinstances.setName method.

    POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME/setName{  "currentName": "VM_NAME",  "name": "NEW_VM_NAME"}

    Replace the following:

    • PROJECT_ID: the ID of the project where the VM islocated.

    • ZONE: the zone where the VM is located.

    • VM_NAME: the name of an existing VM.

    • NEW_VM_NAME: the new name for the specified VM.

    Renaming the VM can take up to a minute to complete. To monitor thestatus of the renaming, poll the operation ID returned by the renameAPI. For more information, seeHandling API responses.

  3. If you need to,restart the VM.

What's next

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.