Search code examples
google-cloud-platformgoogle-compute-engine

Change internal static IP address of Google Cloud Compute Engine Instance in Console


I have an existing Cloud Compute Engine instance that was mistakenly assigned the wrong static internal IP.

I cannot figure out a way to modify the internal IP address to the correct value using the Console or other means. I have tried reserving a new static internal IP, which is easy enough, but there is no way to assign it to an existing resource.

I am talking about Google Console -- not the OS. I know how to change the value in the OS itself.

When I view the resource directly on Google Console and try to edit nic0 in the Google Console, it does not give me any option to modify the existing static IP to a different address. It just says "static ip: 10.x.x.x".

I could easily enough just nuke this resource and make a new one, except for the policy of not being able to re-use the resource name. And I want this specific resource name, so killing it or cloning it is not an option. I just need to modify it's internal IP!

Edit to add: To be clear, I have no problem stopping the instance. I just don't want to destroy it due to reserved naming policy preventing re-use of resource names. I need to modify an in-place resource to a new internal static reserved IP.


Solution

  • Once you have a VM instance created, you cant change internal IP. It is mentioned explicitly.

    The only option you have is to create a new VM with a static IP. You can make a snapshot of the disk from the VM you are using, then create a new VM from that disk marking --private-network-ip.

    Create a disk from a snapshot:

    gcloud compute --project "your-project" disks create "instance-x" \
    --size "100" 
    --zone "europe-west1-c" \
    --source-snapshot "snapshot-x" \
    --type "pd-standard" 
    

    Use the disk to create a new VM with a predefined internal IP:

    gcloud compute --project=your-project instances create instance-x \
    --zone=europe-west1-c \
    --private-network-ip=your-ip \
    --disk=name=instance-x,device-name=instance-x,mode=rw,boot=yes,auto-delete=yes