VMware VIX – Changing IP’s of a Guest VM

by bunchc on December 12, 2008

As a demonstration of the power of VIX, I’ve chosen to show you how to change IP addresses of a Windows VM. You may want to buckle up for this.

First, grab the VIX API installable from VMware’s site. In this case we’ll be using the Windows version (because that is the VM I happen to be writing this post from). The install is quick and puts all the files into “%PROGRAMFILES%\VMware\VMware VIX”.

Lets get our command prompt open:
2008-12-11_2236

Cool, now lets check the IP of our Windows VM:

2008-12-11_2313

Now, lets change it:

C:\Program Files\VMware\VMware VIX>vmrun -T esx -h https://esx.example.com/sdk -u nerv\cody.bunch -p apassword -gu Administrator -gp anotherpassword  runProgramInGuest “[sanstorage1] test/test.vmx” c:\windows\system32\netsh int ip set address “Local Area Connection” static 192.168.15.25 255.255.255.0 192.168.15.1

(That is all one line, the blog wrapped it)

Now for the lovely error!

2008-12-12_1214

Not rightly sure on that one. I’ve opened an SR for it. We’ll see how it goes.

  • Pingback: Professional VMware » Blog Archive » VIXated with VMware’s VIX

  • Ravi

    i tried the above command replacing the respective gateway and ips …. it says “Error Unable to connect to host” … Am i supposed to replace anything else in the command other than the IPs ???

  • http://professionalvmware.com professionalvmware

    There is quite a bit that needs to get changed…See the bracketed parts below.

    vmrun -T esx -h [youresxhosthere] -u [esx user] -p [esx password] -gu [Guest User] -gp [Guest Password] runProgramInGuest “[Path] to/the.vmx” c:windowssystem32netsh int ip set address “Local Area Connection” static 192.168.15.25 255.255.255.0 192.168.15.1

  • http://www.freepatentsonline.com james

    I saw http://professionalvmware.com/2008/12/12/vmware-vix-changing-ips-of-a-guest-vm/ and wanted to mention a useful site: http://www.FreePatentsOnline.com

    It provides free patent searching, free PDF downloading, allows annoting documents and sharing them, and free alerts for new documents.

    If you have a spot, a link to let your users know abou the site would be great.

  • Jeanine R Brown

    Excellent, entertaining, useful reading, Thanks !!

  • Brian Ashton

    nice article dude

  • http://www.professionalvmware.com bunchc

    Thanks!

  • http://www.breastpumpdeals.com/medela-pump-in-style-advanced-metro-bag.html Medela metro bag

    Thanks for the interesting post.

  • http://professionalvmware.com professionalvmware

    No problem!

  • http://www.club-penguin.org/ ClubPenguinCheats

    Thanks for sharing it. This looks pretty interesting and I'll share it with my friends.
    I hope that we will see more from you.

  • http://professionalvmware.com professionalvmware

    Indeed. Thanks!

  • animal72

    I get a message : can't find the VM
    Everything is fine, host connection works, every path settings are correct … still it won't find the VMX file …

    Thanks for helping me … I'm quite stuck with it.

  • http://professionalvmware.com professionalvmware

    Can you reply with the command line and error you are receiving?

  • animal72

    vmrun -T esx -h esxhostname -u root -p password -gu domainuser -gp password runProgramInGuest “/vmfs/volumes/lunname/file.vmx” c:windowssystem32netsh int ip set address “Local Area Connection” static 10.0.0.10 255.255.255.0 10.0.0.1

    And the message is simply “can't find the VM” … i first had host connection error, but solved it … everything is ok except the VM can't be found.

  • http://professionalvmware.com professionalvmware

    Check that the VM is powered on, and on the host you are connecting to. When
    specifying the host, use the path to the sdk, so https://hostname/sdk.
    Finally, instead of “vmfs/volumes/volume/vm.vmx” I'd use the name & path how
    they appear in the VI Client: “[Volume] vmname/vmname.vmx”.

    Let me know how those changes work out.

    -C

  • animal72

    I already corrected the host part using https://hostname/sdk … i'll try the “[volume] vmname/vmname.vmx” part. Should i add a / between [Volume] and vmname/vmname.vmx ?

    Thanks for your help.

  • http://professionalvmware.com professionalvmware

    “[sanstorage1] test/test.vmx” is what I've used, so no additional / needed.

  • animal72

    Oki, thanks … I'll get back to you. By the way … is Powershell to be installed on the VM ? or can it run remotely from the virtual center ?

  • http://professionalvmware.com professionalvmware

    Depends on what you are trying to do. The PowerCLI can be installed anywhere
    that can connect to your virtual center, and be used to manage it.

    -C

  • animal72

    i installed it on the VC and I just want to change my replicated VM's IP because my desaster recovery VLAN is different from the production one. I have no extended VLANs … so basicaly I can't use VBS and have to do my changes through the VC and address the VM through the host …

    If you have any other idea that may work in this context … I take every advise on the subject.

    Goal is to change all my VMs IP starting from a matching table between the production IP / VMName / Destination IP.
    I also need to update the Gateway, Mask and DNS.

  • http://professionalvmware.com professionalvmware

    The new PowerCLI should have something similar to what you are looking for.
    I'll likely write up a new post with this next week.

    -C

  • animal72

    I tried the command and here's the message :

    Error: Cannot open VM: [snap-30f94840-Cluster-A01-AMS2300-17] Par1CX4-09/Par1CX4
    -09.vmx, The virtual machine cannot be found

    The lun name is correct, so is the machine name, and the files are well present in the mentioned directory …

  • animal72

    I tried the command and here's the message :

    Error: Cannot open VM: [snap-30f94840-Cluster-A01-AMS2300-17] Par1CX4-09/Par1CX4
    -09.vmx, The virtual machine cannot be found

    The lun name is correct, so is the machine name, and the files are well present in the mentioned directory …

  • Nazzareno

    Hi,
    one question: with vmrun the guestos must running in ESX. Is it possible to change the ip address in a guestos Windows that is powered off?

    With Linux I can mount the .vmdk and edit /etc/network/interfaces… but in Windows?

    Thanks,
    Nazzareno

  • cemal dur

    Hello
    I need a script to change of solaris guest's ip address ? is it possible that changing of solaris guest ip without login to solaris os ?

    Thank you.

  • http://www.easyrecovery.co.uk data recovery

    When you run just $net1 in powershell, do you get more than one object returned? If so, you might want to try changing this portion:
    set-vmguestnetworkinterface -vmguestinterface $net1[0]

  • http://vibram4u.com/ moncler outlet store

    Hhe article’s content rich variety which make us move for our mood after reading this article. surprise, here http://music-ofthesun.com/ ” >wslmart.net you will find what you want! Recently, I found some wedsites which commodity is colorful of fashion. Such as xxxxxxxx that worth you to see. Believe me these websites won’t let you down.

  • http://www.saleboots.co.uk ugg boots

    The post of content is very interesting and exciting. I learned a lot from here.The content from simple to complex, so all of you can come in . No matter you want to see what can be found.By the way ,there are some websites is also very wonderful,you can go and see.such as Jordan Pro Classic

  • Tony31

    Did you happen to figure this out? I’m in the same scenario and have zero scripting abilities. Any reference or advice is appreciated.

  • Wuyifan

    hi, i was wondering if this solution would useful for a free license ESXI 4 …
    thx at advance

Previous post:

Next post: