If you need to change your vswitch and port group settings using the service console, esxcfg-vswitch is what you need to use.
If you were "tweaking" ESX network settings via VI Client and lost connectivity you will find these commands very useful.

List all virtual switches and the port group information:
esxcfg-vswitch -l

Switch Name    Num Ports   Used Ports  Configured Ports  MTU     Uplinks
vSwitch0                    64                  9                     64                    1500    vmnic2,vmnic0
PortGroup Name      VLAN ID  Used Ports  Uplinks
Server Network                 41           5               vmnic0,vmnic2
Switch Name    Num Ports   Used Ports  Configured Ports  MTU     Uplinks
vSwitch1                    64                  6                         64               1500     vmnic3,vmnic1
PortGroup Name      VLAN ID  Used Ports  Uplinks
Service Console           35                  1           vmnic1,vmnic3
VMkernel                        35                  1           vmnic1,vmnic3
Switch Name    Num Ports   Used Ports  Configured Ports  MTU     Uplinks
vSwitch2                    64                     1                      64                1500
PortGroup Name      VLAN ID  Used Ports  Uplinks
Internal                               0                0


Delete a port group from a vswitch:
/usr/sbin/esxcfg-vswitch -D "Service Console" vSwitch1

Add a port group to a vswitch:
/usr/sbin/esxcfg-vswitch -A "Service Console" vSwitch1

Set the VLAN ID of a port group:
/usr/sbin/esxcfg-vswitch -p "Service Console" -v35 vSwitch1

Check if virtual switch already exists:
esxcfg-vswitch -c vSwitch2

Create a virtual switch:
esxcfg-vswitch -a vSwitch2

Check if a port group on a virtual switch already exists:
esxcfg-vswitch -C VMotion

Create a port group on a virtual switch:
esxcfg-vswitch -A VMotion vSwitch2

Link a virtual switch to a physical nic:
esxcfg-vswitch -L vmnic2 vSwitch2


Command Options:

/usr/sbin/esxcfg-vswitch
esxcfg-vswitch [options] [vswitch[:ports]]
-a|--add              Add a new virtual switch.
-d|--delete           Delete the virtual switch.
-l|--list             List all the virtual switches.
-L|--link=pnic        Set pnic as an uplink for the vswitch.
-U|--unlink=pnic      Remove pnic from the uplinks for the vswitch.
-M|--add-pg-uplink    Add an uplink to the list of uplinks for a portgroup
-N|--del-pg-uplink    Delete an uplink from the list of uplinks for a portgroup
-p|--pg=portgroup     Specify a portgroup for operation
Use ALL to set VLAN IDs on all portgroups
-v|--vlan=id          Set vlan id for portgroup specified by -p
0 would disable the vlan
-c|--check            Check to see if a virtual switch exists.
Program outputs a 1 if it exists, 0 otherwise.
-A|--add-pg=name      Add a new portgroup to the virtual switch.
-D|--del-pg=name      Delete the portgroup from the virtual switch.
-C|--check-pg=name    Check to see if a portgroup exists.  Program
outputs a 1 if it exists, 0 otherwise.
-B|--set-cdp          Set the CDP status for a given virtual switch.
To set pass one of "down", "listen", "advertise", "both".
-b|--get-cdp          Print the current CDP setting for this switch.
-m|--mtu=MTU          Set MTU for the vswitch. This affects all the nics attached on the vswitch.
-r|--restore          Restore all virtual switches from the configuration file
(FOR INTERNAL USE ONLY).
-h|--help             Show this message.

NOTE: Useful to remember for esxcfg-vswitch use lower case switch for the switches. Upper case switch for port groups.

Share this blog post on social media:

Social Links

Disclaimer

All advice, installation/configuration how to guides, troubleshooting and other information on this website are provided as-is with no warranty or guarantee. Whilst the information provided is correct to the best of my knowledge, I am not reponsible for any issues that may arise using this information, and you do so at your own risk. As always before performing anything; check, double check, test and always ensure you have a backup.

Copyright ©2008-2021 Andy Barnes - Please do not copy any content including images without prior consent!

Designed and Hosted by Andy Barnes

We use cookies

We use cookies on our website. Some of them are essential for the operation of the site, while others help us to improve this site and the user experience (tracking cookies). You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.