Script to Configure ESX vSwitch Network Load Balancing
1.0 Overview
It is possible to script the load balancing of a Virtual Switch by using the vimsh command. The basic command syntax is:
vimsh -n -e "hostsvc/net/vswitch_setpolicy --nicteaming-policy [load balance option] [vSwitch#]"
For each of the 4 load balancing options there is a different command option:
| Load Balance Type | Command Option |
| Port ID | loadbalance_srcid |
| IP Hash | loadbalance_ip |
| MAC | loadbalance_srcmac |
| Failover Only | failover_explicit |
For example to change vSwitch1 from the default Port ID to IP address load balancing the command line would look like this:
vimsh -n -e "hostsvc/net/vswitch_setpolicy --nicteaming-policy loadbalance_ip vSwitch1"
This should help those who like to run automated scripted ESX builds. Note that if using in conjunction with esxcfg commands to create and bind vSwtiches you'll need to run a service management restart and put a 20 second or so sleep to allow background processes to complete, eg: this script creates a vSwitch, labels it Production, binds vmnic 1 & 2 to it, restarts hostd, pauses for 20 seconds then modifies loadbalancing of the vSwitch to the MAC based option.
esxcfg-vswitch -a vSwitch2esxcfg-vswitch -A Production vSwitch2esxcfg-vswitch -L vmnic2 vSwitch2esxcfg-vswitch -L vmnic1 vSwitch2vimsh -n -e "/internalsvc/refresh_network"vimsh -n -e "hostsvc/net/vswitch_setpolicy --nicteaming-policy loadbalance_srcmac vSwitch2"
Thanks to Mike Laverick (RTFM Education) for assisting with this Hot Tip
- Nil
- Nil
Spotlight:
VMware Documentation Downloader v11.08.30
Updated for vSphere 5 - A free tool for those on the move who need information FAST
vSphere 5 License Entitlement Changes
See what has changed in the license entitlement in vSphere 5?
Thin Client vs Zero Client
The differences between Thin and Zero desktop clients for VDI
