ESX Server CLI Switching Configuration

Download Template
CLI commands to create various VMware ESX virtual switches to a basic level. These can be used post-install or as part of a kickstart driven installation. vSwitch0 is created by default with vmnic0 or whatever NIC you tell the installer to boot with via kernel options. The management IP address will by default be on vm kernel NIC vmk0. Hence you should start creating additional switches at vSwitch1, vSwitch2 and vmk NIC's at vmk1 etc. You can also call them something more useful if you like, eg. vTrunk0, SpankyNetSwitch9999. A dedicated vswitch connected for VM networks connects to multiple physical NIC's, MTU is increased to 9000 to support jumbo MTU if iSCSI or other applications/protocols requiring it are used to/from VM's. A dedicated vswitch with two physical NIC's (eg. 2 x 4Gbps pipes out of a Flex10 10G interface) is created for ESX access to iSCSI storage systems. Target iSCSI SAN has four 1G NIC's, so four vmk NIC's are created to allow optimal use of the SAN. A dedicated vswitch with two physical NIC's is created for isolation ESX vMotion and Fault Tolerance networks.

cstubbs
May 17, 2012
Name, eg. vSwitch1

NIC, eg. vmnic0

NIC, eg. vmnic1

Name, eg. Server LAN

VLAN ID, eg. 100

Name, eg. vSwitch2

NIC, eg. vmnic2

NIC, eg. vmnic3

IP, eg. 192.168.255.1

Netmask, eg. 255.255.255.0

NIC, eg. vmk1

IP, eg. 192.168.255.2

NIC, eg. vmk2

IP, eg. 192.168.255.3

NIC, eg. vmk3

IP, eg. 192.168.255.4

NIC, eg. vmk4

Name, eg. vSwitch3

NIC, eg. vmnic4

NIC, eg. vmnic5

IP, eg. 192.168.254.1

Netmask, eg. 255.255.255.0

NIC, eg. vmk5

IP, eg. 192.168.253.1

Netmask, eg. 255.255.255.0

NIC, eg. vmk6

VLAN ID, eg. 101

VLAN ID, eg. 102

# Creates 802.1q trunk for VM network access
esxcfg-vswitch -a %{SWITCH1_NAME}%
esxcfg-vswitch -m 9000 %{SWITCH1_NAME}%
esxcfg-vswitch -L %{SWITCH1_NIC0}% %{SWITCH1_NAME}%
esxcfg-vswitch -L %{SWITCH1_NIC1}% %{SWITCH1_NAME}%
esxcfg-vswitch -A "%{NETWORK0_NAME}%" %{SWITCH1_NAME}%
esxcfg-vswitch -p "%{NETWORK0_NAME}%" -v %{NETWORK0_VLAN}% %{SWITCH1_NAME}%

# Creates dedicated vSwitch for iSCSI networking using two interfaces and four vmk NIC's 
# for optimal multi-pathing to a four path iSCSI target.
esxcfg-vswitch -a %{SWITCH2_NAME}%
esxcfg-vswitch -m 9000 %{SWITCH2_NAME}%
esxcfg-vswitch -L %{SWITCH2_NIC0}% %{SWITCH2_NAME}%
esxcfg-vswitch -L %{SWITCH2_NIC1}% %{SWITCH2_NAME}%
esxcfg-vswitch -A "iSCSI Access" %{SWITCH2_NAME}%
esxcfg-vswitch -A "iSCSI1" %{SWITCH2_NAME}%
esxcfg-vswitch -A "iSCSI2" %{SWITCH2_NAME}%
esxcfg-vswitch -A "iSCSI3" %{SWITCH2_NAME}%
esxcfg-vswitch -A "iSCSI4" %{SWITCH2_NAME}%
esxcfg-vmknic -a -i %{ISCSI_IP_1}% -n %{ISCSI_IP_NETMASK}% -m 9000 -p iSCSI1 %{SWITCH2_VMKNIC0}%
esxcfg-vmknic -a -i %{ISCSI_IP_2}% -n %{ISCSI_IP_NETMASK}% -m 9000 -p iSCSI2 %{SWITCH2_VMKNIC1}%
esxcfg-vmknic -a -i %{ISCSI_IP_3}% -n %{ISCSI_IP_NETMASK}% -m 9000 -p iSCSI3 %{SWITCH2_VMKNIC2}%
esxcfg-vmknic -a -i %{ISCSI_IP_4}% -n %{ISCSI_IP_NETMASK}% -m 9000 -p iSCSI4 %{SWITCH2_VMKNIC3}%
esxcfg-vswitch -p iSCSI1 -N %{SWITCH2_NIC0}% %{SWITCH2_NAME}%
esxcfg-vswitch -p iSCSI2 -N %{SWITCH2_NIC1}% %{SWITCH2_NAME}%
esxcfg-vswitch -p iSCSI3 -N %{SWITCH2_NIC0}% %{SWITCH2_NAME}%
esxcfg-vswitch -p iSCSI4 -N %{SWITCH2_NIC1}% %{SWITCH2_NAME}%

# Creates dedicated vSwitch for vMotion and fault tolerance networks using two interfaces
esxcfg-vswitch -a %{SWITCH3_NAME}%
esxcfg-vswitch -m 9000 %{SWITCH3_NAME}%
esxcfg-vswitch -L %{SWITCH3_NIC0}% %{SWITCH3_NAME}%
esxcfg-vswitch -L %{SWITCH3_NIC1}% %{SWITCH3_NAME}%
esxcfg-vswitch -A "vMotion" %{SWITCH3_NAME}%
esxcfg-vswitch -p "vMotion" -v %{VMOTION_VLAN}% %{SWITCH3_NAME}%
esxcfg-vswitch -A "FaultTolerance" %{SWITCH3_NAME}%
esxcfg-vswitch -p "FaultTolerance" -v %{FT_VLAN}%  %{SWITCH3_NAME}%
esxcfg-vmknic -a -i %{VMOTION_IP}% -n %{VMOTION_IP_NETMASK}% -m 9000 -p vMotion %{SWITCH3_VMKNIC0}%
esxcfg-vmknic -a -i %{FT_IP}% -n %{FT_IP_NETMASK}% -m 9000 -p FaultTolerance %{SWITCH3_VMKNIC1}%

You must be logged in to comment.