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

3

5

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.

Reparation answered 8/7, 2019 at 21:48 Comment(3)
cloud.google.com/compute/docs/ip-addresses/…Spectacled
@JohnHanley that is where I started of course. Nothing there has helped me. Please be more specific as to which section will solve my problem? This clearly says "You cannot change the internal IP address of an existing resource. For example, you cannot assign a new static internal IP address to a running VM instance. You can, however, promote the ephemeral internal IP address of a resource to a static internal IP so that the address remains reserved even after the resource is deleted." --- but my assigned IP is not Ephemeral, it is static. So how do I change an existing static IP to anoth?Reparation
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.Reparation
D
7

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
Depone answered 9/7, 2019 at 9:3 Comment(2)
I marked you as answered even though the truth is, there is no answer due to google's policy of not allowing re-use of resource name, and/or not allowing the changing of an internal IP for an existing resource.Reparation
I recommend you check out @Colour answer below. Because you actually can do it, if you're willing to take an extra step.Crackpot
C
9

As of 2021 the accepted answer is incorrect. You can move the instance with the wrong internal static IP address to a different network and then move it back to the original network: This bizarelly allows you to reassign the internal IP.

Colour answered 24/8, 2021 at 12:49 Comment(1)
Great solution-- this astonishingly works. Totally bizarre as you said, but thank you.Crackpot
D
7

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
Depone answered 9/7, 2019 at 9:3 Comment(2)
I marked you as answered even though the truth is, there is no answer due to google's policy of not allowing re-use of resource name, and/or not allowing the changing of an internal IP for an existing resource.Reparation
I recommend you check out @Colour answer below. Because you actually can do it, if you're willing to take an extra step.Crackpot
R
1

For those who are searching for a way to change internal parameters from a GCP instance without the hassle of recreating it:

Export the instance's config with

gcloud compute instances export $INSTANCE_NAME \
    --project $PROJECT_ID \
    --zone $ZONE \
    --destination=$FILE_PATH

(fill the variables with your parameters)

Edit the file that created by "--destination" and change the resource that you need

gcloud compute instances update-from-file $INSTANCE_NAME \
    --project $PROJECT_ID \
    --zone $ZONE \
    --source=$FILE_PATH \
    --most-disruptive-allowed-action REFRESH
# or
#     --most-disruptive-allowed-action RESTART
# if what you are doing might require a reboot

This procedure saved me when I needed to change "canIPForward" from "false" to "true" without having to recreate the VM.

For more info about that, check this out: https://cloud.google.com/compute/docs/instances/update-instance-properties

Ruysdael answered 2/2 at 12:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.