How To Create vSwitches On A VMware ESXi Host Via The Command Line (via SSH)

There are a number of reasons why you might want to create vSwitches via the command line on a VMware ESXi host. Creating a script to setup vSwitches (and other networking settings) in the command line can be useful when rolling out many ESXi hosts or creating a fast recovery plan for DR.

To create vSwitches in the command line, name them, allocate VLANs and physical NICs to those vSwitches, do the following:

  1. Connect to the ESXi host you want to setup the networking for. You can do this using Putty over SSH
  2. Log in to the VMware ESXi server
  3. Run the following command to create a new vSwitch:
    esxcfg-vswitch -a <vSwitch Name>
  4. Run the following command to add a new portgroup to the vSwitch:
    esxcfg-vswitch -A “<Portgroup Name>” <vSwitch Name>
  5. Run the following command to add a VLAN to the portgroup:
    esxcfg-vswitch -v <VLAN Number> -p “<Portgroup Name>” <vSwitch Name>
  6. Run the following command to restart VMware’s services: restart

If you have the network settings page open in the vSphere Client on the ESXi host you just ran the script against, you will have to navigate to another page and return to the networking tab to see the newly added vSwitch and associated network settings. If the vSwitch you added in the command line still isn’t showing, you may have to hit the refresh button in the vSphere Client.

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)

Leave a comment

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