Reputation: 356
I have a running VM1 (internal IP is: xxx.xxx.0.7). I will create another new VM2 and I want to change the IP of VM1 to any other IP and set the IP of VM2 to "xxx.xxx.0.7". OS of both VM is windows server.
I have found some way to change the IP of a running VM. But I am not sure if that works. Is there any straightforward way to do this?
Thanks in advance!
Upvotes: 5
Views: 3039
Reputation: 81464
You can assign a static internal IP address when the instance is created and not once the VM is running.
To accomplish your goal of creating a new instance using an existing internal IP address:
References:
Upvotes: 2
Reputation: 4443
First - for this operation you will need to stop your VM1. But I believe this is not a concern since you are planning to make VM2 work as VM1.
Second - It's impossible to attach new or existing static internal IP to an existing VM.
If you want to reserve internal IP address for VM2 then the only way I know is the first method I described.
First method - switch disks. Simple but may require some configuration after the switch.
Done. Very simple and elegant. You can then Create another VM using VM1's old disk (which is detached at the moment).
I don't know if there will be any issues with booting Windows or any other running services (that may have depend on the old VM'2 IP) but this is your part.
Second method - switch addresses. More complicated but you may loose your original IP - but if you're the only person having administration rights to this VPC (or a project) then you should be OK.
Ephemeral internal IP addresses: these addresses are available to VM instances and forwarding rules. Ephemeral internal IP addresses remain attached to VM instances and forwarding rules until the instance or forwarding rule is deleted.
Procedure is as fallows (for this example my VPC network name was default
- if yours is names otherwise please make proper changes).
lan1
(or whatever you like)lan1
(select ephemeral internal IP address):ip1
lan1
and select "Ephemeral (automatic) as Primary Internal IP:default
and select as "Ephemeral (custom)" Primary Internal IP and type the noted earlied IP in the "address" field.
Why going through lan1 ? For some reason GCP console refuses to change even ephemeral (custom) address to different one:
This way you end up with VM2 having address you wanted.
If you want it to be a static one you need to promote it.
Both methods minimise the downtime to a couple of minutes.
If you're OK with a longer downtime and can create&configure you new VM quick then you can turn off VM1, change it's IP, reserve it as a new static internal IP and then create VM2 with that IP.
Upvotes: 1
Reputation: 76859
This should be possible, while you'd have to use a temporary third one IP address, in order not to produce a duplicate address conflict among one of the other two addresses, while changing them. They MUST be unique at any time, else you'll have a routing problem. The most straightforward might be to use both server's serial consoles, because these would not care about temporary IP address conflicts. The crux is, that one cannot change both at precisely the same time, and as soon as having produced the duplicate IP address, one may want to resort to the serial console anyway.
Upvotes: 0