Setting VMware ESX vSwitch Load Balancing Policy via CLI

I see this question popping up a lot, so I thought I’d just throw up this quick blog entry with the command that’s necessary to set the load balancing policy for a VMware ESX vSwitch.

In VMware ESX 3.5 U2 (which users should be using if at all possible, now that it’s validated by Microsoft), the command to do this is vmware-vim-cmd:

vmware-vim-cmd /hostsvc/net/vswitch_setpolicy
--nicteaming-policy=loadbalance_ip vSwitch1

This command sets the vSwitch to use “Route based on ip hash”. To set the vSwitch back to “Route based on the originating virtual port ID”, use this command:

vmware-vim-cmd /hostsvc/net/vswitch_setpolicy
--nicteaming-policy=loadbalance_srcid vSwitch1

Obviously, users will need to replace vSwitch1 with the appropriate vSwitch that needs to be configured. Note that this command is a bit different than in earlier versions, which used vimsh.

I hope this is useful!

Tags: , , ,

  1. Duncan’s avatar

    Keep in mind that if you want to do a scripted install you will need to setup the server that it can have atleast 2 active nics. from the installer normally if you add a nic and set the switch to load balancing on ip you would still only have 1 active nic.

    i used the following for the second vswitch (0001), so i set the value “1″ to “two” in the esx.conf file:

    /bin/sed -e ’s/net\/vswitch\/child\[0001\]\/teamPolicy\/maxActive = \”1\”/net\/vswitch\/child\[0001\]\/teamPolicy\/maxActive = \”2\”/g’ /tmp/esx.conf.bak >> /etc/vmware/esx.conf

  2. slowe’s avatar

    Good point, Duncan! Thanks for adding that information to the conversation.

  3. ccassel’s avatar

    Is there any difference between modifying the esx.conf and adding two active nics using vswitch_setpolicy or portgroup_set from vmware-vim-cmd? I’ve been doing it like this in my post script, which works as far as I can tell:
    esxcfg-vswitch -a vSwitch2
    esxcfg-vswitch -L vmnic4 vSwitch2
    esxcfg-vswitch -L vmnic6 vSwitch2
    esxcfg-vswitch -L vmnic8 vSwitch2
    vmware-vim-cmd hostsvc/net/refresh
    vmware-vim-cmd hostsvc/net/vswitch_setpolicy –nicorderpolicy-active=vmnic4,vmnic6 –nicorderpolicy-standby=vmnic8 –nicteaming-policy=loadbalance_ip vSwitch2

  4. Jay’s avatar

    I would like to set up multiple vSwitches to utulize one physical nic. I am unable to locate how to add an ip to a second, thrid, or fourth nic and assign that nic to an active state. Can you help ?

  5. slowe’s avatar

    ccassel,

    I’m not aware of any difference, other than modifying esx.conf is strongly discouraged.

    Jay,

    AFAIK there is no way to do it. A physical NIC (pNIC) can be bound to only one vSwitch at a time. The opposite–binding multiple pNICs to a single vSwitch–is easily accomplished via the command line above.

    Hope this helps!

  6. Bevan’s avatar

    Could you supply any instructions on how to do it for ESX 4.0/4.1?
    We keep getting “Call “HostNetworkSystem.UpdateVirtualSwitch” for object “networkSystem” on ESX “server” failed.” when trying to do it in the GUI.

  7. slowe’s avatar

    Bevan, if you’re having problems setting this value via the GUI, then you most likely have an issue that needs to be resolved. I’d suggest opening a case with VMware support.

  8. David’s avatar

    this command actually saved my life today!
    changed load balancing policy in the VI-Client on one of the ESX Host in a HA Cluster from “route based on IP Hash” to “Route based on originating virtual port ID” in an attempt to troubleshoot a network timout issue and the host became unmanagable.
    Unfortunately customer had Service Console network on the same network.
    Anyway we managed to log on to the iLO remote console and so I was able to execute this command to change the policy back to “Route based on ip hash” and after the host went down and rebooted, the host was reachable and manageable again. Luckily HA kicked in and restarted the VMs on the other Host so the downtime was minimal.
    Had to troubleshoot HA a bit after that, but without this command I would have had to drive to the customer and try fix it from there.

    Thanks a lot.