You’re familiar with features in VMware vSphere that can help bring up critical virtual infrastructure after a widespread datacenter outage — planned or otherwise — but did you also know that it’s possible to power on a virtual machine and even determine the dynamic IP address of a guest OS using a simple command-line utility? This could be handy after a disaster or if you normally rely on a Windows virtual machine to run the vSphere Client and don’t feel like firing up Fusion for one quick task.
Power on and SSH to a Linux VM from Mac OS X
Consider this real-world situation: You are working remotely on your Mac and need to log into a powered-off Linux VM back in the datacenter. Don’t fret — if you can ssh to the host using Tech Support Mode (VMware ESXi 4.1 shown here), you are most of the way there. Thanks to vim-cmd you can find your VM, power it on, and learn the guest OS IP address in no time:
Let’s break it down step by step:
1. Use grep to find the ID of your VM (1008 in this example):
~ # vim-cmd vmsvc/getallvms | grep -i CENTOS1 1008 CENTOS1 [CX4-01-LUN9] CENTOS1/CENTOS1.vmx centos64Guest
2. Quick sanity check to verify the VM is actually powered off:
~ # vim-cmd vmsvc/get.summary 1008 | egrep '(power|ip)' powerState = "poweredOff", ipAddress = ,
3. Power on, wait a few moments, and check status again:
~ # vim-cmd vmsvc/power.on 1008 Powering on VM: ~ # vim-cmd vmsvc/get.summary 1008 | egrep '(power|ip)' powerState = "poweredOn", ipAddress = "10.136.234.38", ~ #
4. Connect with ssh (or RDP, if targeting a Windows VM) and get on with things
Enjoy!
Thanks for the steps.
It looks like you have to have VMWare guest tools installed in order to get the ip address this way. Is this true?
~ # vim-cmd vmsvc/get.summary 16 | egrep ‘(power|ip)’
powerState = “poweredOn”,
ipAddress = ,
We don’t install the guest tools:
guest = (vim.vm.Summary.GuestSummary) {
dynamicType = ,
guestId = ,
guestFullName = ,
toolsStatus = “toolsNotInstalled”,
toolsVersionStatus = “guestToolsNotInstalled”,
toolsRunningStatus = “guestToolsNotRunning”,
hostName = ,
ipAddress = ,
},
Yes. You are running Tools aren’t you?
Very thanks for it! You are safe my life! 🙂
sorry for my english (:
Im lost vCenter on blade array, and i’l need up it. Very thanks for help!
Hi,
I don’t find IP address in VM summay tab, when i grep the VM summary for IP details using vim-cmd vmsvc, i get the output of ipAddress=
Sample output:
~ # vim-cmd vmsvc/get.summary 9408 | egrep ‘(power|ip)’
powerState = “poweredOn”,
ipAddress = ,
~ #
please advise on this, how to edit the VM details by using vim-cmd to set the ipAddress.