Virtual Machine, IP Address, and MAC Address: Frequently Confused Concepts

Having answered many questions about IP addresses of virtual machines at different occasions, I still see more are coming. I think it’s time to write a blog about it. Hopefully people would search the Internet before raising the question.

First of all, there is a big confusion on the relationship of IP addresses and virtual machines. Many people tend to associate IP addresses with virtual machines, and want to retrieve/change the IP address of a virtual machine.

Lost VMs or Containers? Too Many Consoles? Too Slow GUI? Time to learn how to "Google" and manage your VMware and clouds in a fast and secure HTML5 App.

In fact, a virtual machine is very much like its physical counterpart. It does not have an IP address by itself. In other words, an IP address is NOT an intrinsic attribute of a machine, either virtual or physical. It might have one or more only after an OS is installed. In most cases, it does have one or more IP addresses, which gives the impression that every machine has an IP address.

A virtual machine does have intrinsic attributes such as MAC addresses if NIC cards are configured. Unlike its physical counterpart, a virtual machine’s MAC address can be re-configured. Some software vendors rely on MAC addresses to lock down their licensed software on particular machines. This mechanism can be, therefore, compromised in virtual environments.

Why do people associate IPs with virtual machines? I think it’s mainly because we take a virtual machine as software rather than hardware and most of the time we have OSes preinstalled. Still, we should not confuse its logical responsibility as a machine rather than OS.

Having said that, vSphere API does help to retrieve IP address from the virtual machine if VMware Tools is installed inside the guest OS. It’s the VMware Tools that reports the IP address back.

With this clarified, we can easily understand many different things. Here are several frequently asked questions and answers.

Q: Can I retrieve the IP address of a virtual machine with vSphere API?

A: Yes. But you ***MUST*** install VMware Tools in the OS running on that virtual machine. To get the IP address, you can retrieve the property guest (Type: GuestInfo) of a virtual machine, and get ip address from the GuestInfo object.

Using vSphere Java API, it’s one line call:


Q: Can I change the MAC address?

A: Yes.  You want to call ReconfigVM_Task() defined with VirtualMachine. The VirtualMachineConfigSpec argument could be tricky. I suggest you to use Onyx to record your manual changes and translate the script to Java code.

Q: Can I change the IP address of a virtual machine with vSphere API?

A: Yes. You can change the IP address via customization as part of cloning, or customize an existing VM’s guest OS. Alternatively, you can connect to the guest OS if you have the IP of an existing VM’s guest OS.

The key to the customization via API is to understand the CustomizationSpec. Again the VMware Tools is required at the guest OS. Depending on the type of OS to customize, you may need Microsoft Sysprep tools installed on the vCenter server.

In general, you want to look at other approaches, for example configuring DHCP server to assign IPs either dynamically or as you planned based on their MAC addresses. In vApp, you can also think about the IP pool for assigning IP addresses.

This entry was posted in vSphere API and tagged , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.


  1. Posted December 13, 2010 at 10:43 am | Permalink

    Hey , I have one more question. I have four nics configured with DHCP settings, but I have eth1 as my management interface, how can I get the IP address for eth1 which is the dhcp address, if I do vm.getGuest().getIpAddress(); it is giving me IP address of eth0.

  2. Posted December 13, 2010 at 11:27 pm | Permalink

    Have you checked the “” property (type: GuestNicInfo[])? It should have the IP addresses associated with other NICs.

  3. Posted December 14, 2010 at 10:14 am | Permalink

    Hi Steve,
    Thanks for the help, actually GuestNicInfo was returning the ip address as array of Strings which caused confusion.

  4. sasidhar
    Posted September 22, 2011 at 11:52 pm | Permalink


    can anyone has idea how to set/change the ip adress of VM. If So can anyone share the code..

  5. jayadev
    Posted May 19, 2012 at 3:33 pm | Permalink

    Have any tried vSphere web svc with REST?

  6. kevin
    Posted May 23, 2012 at 5:20 am | Permalink

    Q: Can I change the IP address of a virtual machine with vSphere API?

    A: Yes. You can change the IP address via customization as part of cloning, or customize an existing VM’s guest OS.

    can you give a simple example how to do it by using the way of customize an existing VM’s guest OS? i need to change the ip address of vm but from the sdk i cannot find the interface to do it,thanks

  7. Posted May 23, 2012 at 11:01 pm | Permalink
  8. santhosh
    Posted November 5, 2012 at 11:54 am | Permalink

    I am running 2 VM machines in my physical machine. Can You tell me how i connect the folders of those 2 machines each other using their IP addresses?(I am using windows 7 operating system in my physical and as well as virtual machines )

  9. yasaswi
    Posted March 1, 2013 at 4:12 am | Permalink

    i want to know code for knowing network address and status of guest os whether they are power on or off..i tried the above code vm.getGuest().getIpAddress(); but im getng null

  10. Posted March 1, 2013 at 11:36 am | Permalink

    It happens if you don’t have VMware Tools installed. Even if you have the Tools installed, it takes a little time for the IP to be sent back.

  11. Xiang Ren
    Posted August 8, 2013 at 12:34 am | Permalink

    Hi, I have difficultities in set the CustomizationSpec to change IP address through the CloneVm_Task() function, could you please give some more details about the code to change IP address? Thank you very much! BTW, I used .NET as programming tool, should it be much different from Java?

  12. Posted August 12, 2013 at 2:02 am | Permalink

    Hi Xiang,

    Using .NET as programming tool is not allowed as we are all Java here. :) In truth it doesn’t matter as it’s based Web Services. I suggest you to use DoubleCloud proxy to record how vSphere Client does it.

    Best luck!


  13. maharani
    Posted August 29, 2013 at 5:44 am | Permalink

    @Xiang Ren
    Hi Xiang,

    I used with C# as based language to clone VM and change the IP.
    The code is work and the IP changed.
    FYI I used vim25api. Here is the code.

    VirtualMachineCloneSpec cloneSpec = new VirtualMachineCloneSpec();
    string guestCustomizationScript = “your guest customization script name”;

    //get your customization spec item by name.
    CustomizationSpecItem cusSpecItem = _service.GetCustomizationSpec(_sic.customizationSpecManager, guestCustomizationScript);
    cloneSpec.customization = cusSpecItem.spec;

    CustomizationFixedIp fixedIP = new CustomizationFixedIp();
    fixedIP.ipAddress = ipAddress;
    cloneSpec.customization.nicSettingMap[0].adapter.ip = fixedIP;

    ManagedObjectReference cloneTask = _service.CloneVM_Task(vmRef, vmFolderRef, cloneName, cloneSpec);

  14. apapap
    Posted September 27, 2013 at 1:20 am | Permalink

    I am getting the following error :
    “Exception in thread “main” com.vmware.vim25.NotFound” on the following line:
    “CustomizationSpecItem cusSpecItem = _service.GetCustomizationSpec(_sic.customizationSpecManager, guestCustomizationScript);”
    I guess it cannot find the “guestCustomizationScript”.
    Can you please help me with this?

  15. Posted July 23, 2015 at 5:54 am | Permalink

    Hi Steve,

    Can you tell me what would be the dot notation to get the list of ipaddresses for a VM using the property collector considering that the VM might have multiple nics? I’m getting a blank after: since ipconfig itself can be an array

  16. Posted July 23, 2015 at 9:55 pm | Permalink

    The dot notation can not traverse the array. If you need to have something with an item in the array, get the array first before locating the item. Hope it helps.


  17. Manish Shenoy B
    Posted January 14, 2016 at 2:08 am | Permalink

    Hi Steve,

    I know this thread is almost 5 years old, but can you please advice me on a problem?
    I am trying to change the IP address of an offline VM. But, once I have made changes in the registry – System\ControlSet001\Services\Tcpip\Parameters\Interfaces\GUID , I try to boot the system and I see that dual IP has been assigned to the VM in the Network settings advanced option, even when I have over-written the IPAddress. The newly assigned IP has has been showing as a secondary IP and the old IP is the primary IP. Is there a way to delete the traces of the old IP?

    Please advice.

  18. Melvin Moses
    Posted August 19, 2016 at 7:09 am | Permalink

    Hi Steve,

    I’m a beginner in VMware. I’m using the SDK for cloning the vm. Can you please get me some java samples of vmware customization or links. It would be very grateful.

  19. Posted August 23, 2016 at 1:01 pm | Permalink

    Hi Melvin,

    You may want to explore the samples we have at Look at the right side for the link.


  20. Melvin Moses
    Posted August 23, 2016 at 11:57 pm | Permalink

    Hi Steve,

    Thanks for your input. But I’m not looking for VI java API samples on customization. I’m needing some java samples on networking customization using VSphere SDK 6.0. Can you direct me to some samples or links. Thanks in advance.

    Melvin Moses

  21. Posted August 24, 2016 at 2:26 am | Permalink

    You are very welcome Melvin,

    If there are samples, you should be able to find them in the vSphere SDK download. Another place for help is the VMware community. Good luck!


Post a Comment

Your email is never published nor shared. Required fields are marked *


You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>


    My company has created products like vSearch ("Super vCenter"), vijavaNG APIs, EAM APIs, ICE tool. We also help clients with virtualization and cloud computing on customized development, training. Should you, or someone you know, need these products and services, please feel free to contact me: steve __AT__

    Me: Steve Jin, VMware vExpert who authored the VMware VI and vSphere SDK by Prentice Hall, and created the de factor open source vSphere Java API while working at VMware engineering. Companies like Cisco, EMC, NetApp, HP, Dell, VMware, are among the users of the API and other tools I developed for their products, internal IT orchestration, and test automation.