vSwitch rescue from the CLI

Virtual Distributed Switches have many advantages over standard switches. Because you have a centralized configuration over all hosts they’re less error prone to configuration errors than standard switches. Call me old fashioned but I prefer to have at least the hosts management interface on a standard switch. In case something bad happens, you can still access the host and make changes on the interface.

Recently a customers host had failed. After restoring configuration, for some reason vmnics were swapped between vdSwitches and it wasn’t possible to configure that host neither with hostclient nor with vCenter. The customer was short on vmnics in the past and has configured Management Network on a distributed Portgroup on a distributed vSwitch. This is legal and usually not a problem. In that special case it was a problem. I was literally locked out of the host. Reassigning NICs in the DCUI didn’t work, because they were all claimed by Distributed-vSwitches thus not available for standard switches.

What now ?

There’s help, but you need to access the CLI of DCUI.
Login to DCUI console, select “Troubleshooting Options” in the main menu.

In Troubleshooting section select “Enable ESXi Shell”.

On the right hand side you can see the current status of the ESXi Shell.

Press [Alt] + [F1] to access the shell and login as user root.

Add new Standard Switch

Add a standard vswitch with name vSwitch1 (or any other non-existing name).

esxcli network vswitch standard add -v vSwitch1

Now, let’s have a look at our distributed vSwitches. We need to unclaim a vmnic from the dvSwitch to use it with the new standard switch vSwitch1.

esxcli network vswitch dvs vmware list

You’ll get a long list with switch details, ports and connected clients. Look for the line “Uplinks:”. There you’ll see all vmnics used as uplinks on that dvSwitch.

Drop vmnic from vDS

Select a vmnic to drop from the vdSwitch. In our example vmnic0 and vmnic1 are connected to the distributed vswitch. Port ID of vmnic0 is 18 and name of the dvSwitch is dvs-LAN-1.

esxcfg-vswitch -Q <vmnic> -V <uplink port ID> <dvS-name>

In our example the command would be:

 esxcfg-vswitch -Q vmnic0 -V 18 dvs-LAN-1

An alternate (modern) command is vicfg-vswitch (vSphere4 and later):

vicfg-vswitch -Q <vmnic> --dvp <uplink port ID>  <dvswitch_name> 

It is recommended to use the vicfg-vswitch command instead of esxcfg, which will become obsolte in the future.

 vicfg-vswitch -Q vmnic0 --dvp 18 dvs-LAN-1 

Add vmnic to standard switch

esxcli network vswitch standard uplink add --uplink-name=vmnic0 --vswitch-name=vSwitch1

Now you have standard switch with one uplink (vmnic0). You may now configure that NIC for management in the DCUI.

Logout from ESXI Shell and switch view to DCUI with [Alt] + [F2]. Select “Disable ESXi Shell”.

Revert Settings

To remove a vmnic from a standard switch, issue this command.

esxcli network vswitch standard uplink remove –uplink-name=vmnic0 –vswitch-name=vSwitch1

Add vmnic0 back to distributed vSwitch dvs-LAN-1. We need to find an unclaimed port ID for vmnic0. I chose 39 in the example below.

  esxcfg-vswitch -P vmnic0 -V 39 dvSwitch1 

List all standard vSwitches.

esxcli network vswitch standard list 

You’ll get a list of all standard switches. The vSwitch created in the beginning (vSwitch1) should be listed here too, but the line “Uplinks:” should be empty, because we’ve removed vmnic0.

Remove standard switch

To remove our empty vSwitch1 we can issue this command:

esxcli network vswitch standard remove -v vSwitch1

Links

KB 1008127 – Configuring vSwitch or vNetwork Distributed Switch from the command line in ESXi/ESX

VMware code – vSphere Command-Line Interface Reference

Leave a Reply

Your email address will not be published. Required fields are marked *