Fabian Jakobs
Fabian Jakobs

Reputation: 29153

Can I change the network of an existing Google Compute Engine VM

I have a couple of Google Compute Engine (GCE) virtual machines spread across two GCE networks. Now I want to move them all to one shared network but I can't find a way to change the network of an existing VM. Is there a way to do this or do I have to recreate the VMs in the new network?

Upvotes: 8

Views: 16319

Answers (5)

Ian Newland
Ian Newland

Reputation: 81

Google has recently added this feature and you are now able to edit the network.

Simply select the VM you want to change the network for and hit the 'Edit' button at the top. Then scroll down to 'Network Interfaces' and you will see a pencil next to the nic.

network interface

Upvotes: 8

Jason Tarr
Jason Tarr

Reputation: 331

Just create a snapshot of the vm instance, then create a new vm instance from that snapshot and specify a different network.

Upvotes: 2

Chris Eck
Chris Eck

Reputation: 22

Yes, you can do this and it's quite simple.

Use the Instance-DeleteAccessConfig and Instace-AddAccessConfig methods to hot-remove & hot-add network configurations on running instances.

In this case, you'll first call deleteAccessConfig on the instance to remove it from the first network, then call addAccessConfig to add it to the second.

Documentation here: https://developers.google.com/compute/docs/reference/latest/instances/deleteAccessConfig https://developers.google.com/compute/docs/reference/latest/instances/addAccessConfig

Upvotes: -1

Hanxue
Hanxue

Reputation: 12766

Google Developers Console

Although you cannot directly move an instance, the Google Developers Console now has the function to Clone this instance. Go to Google Developers Console, navigate to Project ID -> Compute Engine -> VM Instances -> . Scroll down to the end and you should see the option

Google Cloud Console

After clicking on Clone this instance, you will be brought to the new instance creation page, with an option to select which Zone you wish to clone the target instance.

Create new instance


gcutil

You can use the gcutil moveinstances command to move an instance from a zone to another zone. You can even move a list of instances using regular expression, for example:

gcutil moveinstances --source_zone=zone-a
                             --destination_zone=zone-b "i-[0-9]" "b-.*"

For more information, type gcutil help moveinstances

Upvotes: 5

Brian Dorsey
Brian Dorsey

Reputation: 4688

You have to recreate the VM's in the new network.

Upvotes: 8

Related Questions