Sometimes VMs need to have their IP changed. And sometimes you waited to long to change the IP and you can no longer access your VM. There could be any number of reasons for this to happen, however when it happens, you are stuck doing a “Console” from vCenter to get into your guest.
Don’t get me wrong, the console has gotten SIGNIFICANTLY better over the last few years, and some may even use it as a Remote Desktop(RDP) substitute. But for others, it can be annoying to have to use the Console to have to get into a VM. I know, First World Problems right?!
Never fear my fellow Noobs, you don’t have to use the Console if you want to change the IP of a VM. You can use PowerCLI! Specifically the two cmdlets we will use are Get-VMGuestNetworkInterface and Set-VMGuestNetworkInterface.
Quick Side-Note: Although these two cmdlets have been around for a while they have recently…like last 6 months or a year…have gotten much more user friendly. There used to be requirements about what kind of boxes you could run them from or against(like x86 or x64 type stuff). I don’t remember specifics but long story short… Essentially if you have issues with these cmdlets, install the latest version of PowerCLI and try again 🙂 (Edit: I was told I may not have been specific enough here…if you have questions about this, check out these release notes. Or post a comment! http://www.vmware.com/support/developer/PowerCLI/PowerCLI51/powercli51-793510-releasenotes.html)
First let’s see what IP the VM is working with…
Notice three things about this first screen shot.
- I specify the VM I want to run the command against (testcr)
- I decide to supply a different set of credential than the ones I am running Powershell/PowerCLI with…
- The output is several network interfaces on the guest
Get-VMGuestNetworkInterface testcr -GuestCredential (Get-Credential) |Where-Object { $_.ip -ne $null} |Set-vmguestnetworkinterface -ip “10.22.15.168” -netmask “255.255.255.0” -gateway “10.22.15.1” -GuestCredential (Get-Credential)
2 Comments
Nathan · October 19, 2012 at 5:26 pm
Nice post, how about ipv6? does it support ipv6?
C-Rad · October 19, 2012 at 5:46 pm
AWESOME Question… What I am seeing/hearing is pre 5.1 it still didn’t support ipv6. I am honestly not sure about 5.1 though.