- This command is one of the most useful commands in the service console. This command allows you to list, add, modify or delete virtual Ethernet switches on an ESX host. The simplest option with this command is the -l option to list the virtual switches and portgroups defined on the host.[root@esx1host root]# esxcfg-vswitch -lIf you are having problems with your ESX server after an in-place upgrade, this tool is invaluable in resolving the problems with service console networking. The output of this command is initially a little intimidating. It is best to keep in mind the network topology:Service Console IP Interface (vswif0) —- connected to —-> Service Console Port on vSwitch —– up-linked to —-> vmnic
Where a vmnic is a physical Ethernet adapter.
If we wish to view the same information at the service console command line, we would use the esxcfg-vswitch command with the “-l” switch to list the defined virtual switches.
[root@esx1host root]# esxcfg-vswitch -l
Switch Name Num Ports Used Ports Configured Ports Uplinks
vSwitch0 32 4 32 vmnic0
PortGroup Name Internal ID VLAN ID Used Ports Uplinks
Service Console portgroup0 0 1 vmnic0
NFS access portgroup1 0 1 vmnic0
If we wanted to add another virtual Ethernet switch, we would use esxcfg-vswitch command with the “-a” switch. Note that the -a is specified in lowercase. Take care to ensure you have specified lowercase because uppercase “A” performs a different function with this command. So, lets add a new virtual switch to our ESX host called vSwitch1 and then list the switches to check our command has worked ok.
[root@esx1host root]# esxcfg-vswitch -a vSwitch1
[root@esx1host root]# esxcfg-vswitch -l
Switch Name Num Ports Used Ports Configured Ports Uplinks
vSwitch0 32 4 32 vmnic0
PortGroup Name Internal ID VLAN ID Used Ports Uplinks
Service Console portgroup0 0 1 vmnic0
NFS access portgroup1 0 1 vmnic0
Switch Name Num Ports Used Ports Configured Ports Uplinks
vSwitch1 64 0 64
PortGroup Name Internal ID VLAN ID Used Ports Uplinks
Notice that the number of ports on the virtual switch is 64 on the newly created switch. The original virtual switch has only 32. This difference arises between creating the switch in the VI Client or the command line. Notice also that the used port count doesn’t immediately make sense. Each VM consumes a port, each vmnic consumes a port and the uplink itself consumes a port. Anyway, if you are like me and you can never remember which case of the letter “a” to use when adding a virtual switch, then use the esxcfg-vswitch command with the –add switch when creating a new switch like this:
esxcfg-vswitch –add vSwitch2
which I think is a little clearer to understand.
Now if we want to add a portgroup to the new virtual switch we have created, we can use the esxcfg-vswitch -A command. It does not matter whether you are creating a service console port, a VM port group or a VMkernel port when creating a port group; the way we create the connection to the virtual switch always starts out the same in the command line. Only after creating the port group do we then specify if it is to be anything other than a VM port group. In the following commands, we add a new portgroup called “Production” on the virtual switch vSwitch1.
[root@esx1host root]# esxcfg-vswitch -A “Production” vSwitch1
[root@esx1host root]# esxcfg-vswitch -l
Switch Name Num Ports Used Ports Configured Ports Uplinks
vSwitch0 32 4 32 vmnic0
PortGroup Name Internal ID VLAN ID Used Ports Uplinks
Service Console portgroup0 0 1 vmnic0
NFS access portgroup1 0 1 vmnic0
Switch Name Num Ports Used Ports Configured Ports Uplinks
vSwitch1 64 0 64
PortGroup Name Internal ID VLAN ID Used Ports Uplinks
Production portgroup2 0 0
Alternatively you could use the following command to add a port group to a virtual switch.
[root@esx1host root]# esxcfg-vswitch –add-pg=”Production” vSwitch1
This alternative switch of using –ad-pg I think is clearer for understanding what the command is doing. The –add-pg option can clearly be seen to add a portgroup to a virtual switch, and again is simpler to understand than just “-A”. The portgroup name in our example is called “Production”, but it can be what you want. We recommend adoption of a standard across all your virtual infrastructure. I have seen some clients align their portgroup names with the IP subnets, so you could have a portgroup called something like “192.168.1.0 subnet”.
Although we have now created a new virtual switch and have created a VM port group on it, the virtual switch itself does not have any uplinks. Remember that when we bind a physical network adapter to a virtual switch we are uplinking a vmnic to the switch and the switch then “owns” that adapter, i.e. it is not available to be used by any other virtual switches. We perform the uplink by using the esxcfg-vswitch command with the -L switch for link.
[root@esx1host root]# esxcfg-vswitch -L vmnic1 vSwitch1
So in one simple command we have linked the physical network adapter vmnic1 to our new virtual Ethernet switch vSwitch1. If we then realised we had used the wrong physical adapter, we can just as easily unlink with -U. In the next example, we swap the uplinked vmnic1 for an alternative adapter vmnic2
[root@esx1host root]# esxcfg-vswitch -U vmnic1 vSwitch1
[root@esx1host root]# esxcfg-vswitch -L vmnic2 vSwitch1
This changing of vmnic bound to a virtual switch is often required post-installation, as we may select the wrong physical adapter to use for the service console during the install and need to correct our configuration before we can connect to our host with VI client!
As of ESX 3.5, VMware added Cisco Discovery Protocol (CDP) support for virtual switches. We can view CDP information of the current neighbour of the physical NIC. In the VI Client, we can see this by clicking on the
To display the CDP configuration setting for a virtual switch, we use the lowercase b switch, where we will find which of the four CDP modes it is in: disable, listen, advertise or both.
[root@esx1host root]# esxcfg-vswitch -b vSwitch0
listen
We can change the CDP mode with the -B (uppercase) option. Here we are changing virtual switch called vSwitch0 to support both advertise and listen.
[root@esx1host root]# esxcfg-vswitch -B both vSwitch0
[root@esx1host root]# esxcfg-vswitch -b vSwitch0
both


Posted in
Tags: