FeedBurner

Enter your email address:


Visitors

Today:7
This month:1226
This year:2868
Total:23935

Online

We have 6 guests online
Creating and managing virtual switches on ESX servers PDF Print E-mail
( 0 Votes )
Written by Cristian Ciobanu   
Monday, 01 August 2011 18:52

Vmware

Introduction



Virtual switches also known as vSwitches are logical switches built into the ESX infrastructure which allows you to connect virtual machines at layer 2 and provide traffic management for virtual machines. A vSwitch has 56 logical ports by default and can be extended up to 4088 ports in vSphere 4. You can create and manage vSwitches through the vSphere Client or through the VMware ESX Service Console using the esxcfg-vswitch command. A vSwitch can be created without any NICs mapped to it, or with one or more NICs mapped to it. If the vSwitch does not have any NICs attached to it is called an internal vSwitch, because it allows communication only within the ESX host. A single ESX host can support up to 127 virtual switches.

vSwitches behave like physical switches in some ways. For example a vSwitch can maintain MAC address tables, forward frames to other switch ports based on the MAC address, support VLAN configurations, is capable of trunking using IEEE 802.1q VLAN tags, and is capable of establishing port channels. On the other hand they miss some features of the physical switches like: support for Dynamic Trunking Protocol (DTP), Port Aggregation Protocol (PAgP) and Spanning Tree Protocol (STP).

Managing vSwitches using command line tools

A default ESX installation has one virtual switch called vSwitch0 which has two port groups, called VM Network and Management Network. A port group defines how a connection is made through the vSwitch to the network. They allows you to define VLANs and operates as a boundary for communication and/or security policy configuration. To manage vSwitches easily in your infrastructure you can use the esxcfg-vswitch command. To use this command you need to have physical access to the ESX server console or have remote SSH access enabled. Before we add a new vSwitch let's review the current configuration by using the esxcfg-vswitch command with the "-l" option.

# esxcfg-vswitch -l
Switch Name      Num Ports   Used Ports  Configured Ports  MTU     Uplinks
vSwitch0         128         3           128               1500    vmnic0
  PortGroup Name        VLAN ID  Used Ports  Uplinks
  VM Network            0        0           vmnic0
  Service Console       0        1           vmnic0

From the above output we can see that there is one virtual switch called vSwitch0 configured which has 128 ports allocated and has mapped a network adapter called vmnic0 which is used by the Service Console portgroup. If you use the vSphere client to see this information you will observe that the total number of ports is 120 because 8 ports are reserved for its own use. Let's add another vSwitch to separate traffic from the Service Console. To do this use the esxcfg-vswitch command with the "-a" option followed by the virtual switch name.

# esxcfg-vswitch -a MySwitch

As you can see I have specified MySwitch as the name for the virtual switch. You can also specify the number of ports to be assigned when creating a new vSwitch by appending a colon ":" after the virtual switch name followed by the desired number of ports. If you specify for example 40 the switch will be created with 64 ports but only 32 will be visible in the vSphere client.

# esxcfg-vswitch -a MySwitch:40

Now let's add a portgroup to our newly created switch. Use the esxcfg-vswitch command with the '-A' option followed by the portgroup name.

# esxcfg-vswitch -A Accounting MySwitch

Again if you display the virtual switch configuration using the '-l' option, you will notice that the Accounting portgroup has been added under MySwitch but that it has not yet been assigned to an uplink. Then we need to add the physical NIC to our newly created virtual switch. Use the following command:

# esxcfg-vswitch -L vmnic2 MySwitch

In my scenario I have mapped the physical adapter vmnic2 which will be used by a virtual machine to connect to the virtual switch MySwitch. If you have multiple physical adapters and by mistake assigned the wrong one to the virtual switch you can remove it using the '-U' option of the esxcfg-vswitch command:

# esxcfg-vswitch -U vmnic2 MySwitch

Let's assume we have several virtual machines and we want to separate them by using different portgroups and VLANs. By using VLANs you can reduce the number of physical adapters and virtual switches needed for your network. Thus a single virtual switch with only one physical adapter assigned to it can split the traffic between the virtual machines. In order to create a VLAN for a specified portgroup type the following command:

# esxcfg-vswitch -v 101 -p LinuxServers MySwitch

Here I have set the VLAN ID using the '-v' option to 101. The portgroup specified using the '-p' option must exist otherwise you'll reveive the following error message:

No such portgroup: LinuxServers under vswitch:MySwitch

If you need to remove the VLAN ID for specific portgroup use '0' as the value for the '-v' option. Vmware vSwitches also support the Cisco Discovery Protocol (CDP) which allows to share physical and virtual switch configurations. By default all vSwitches are in listen mode which allows a vSphere Client to display CDP data of the physical switch. You can verify the CDP status for a specific vSwitch using the following command:

# esxcfg-vswitch -b MySwitch

Virtual switches support four CDP modes: listen(default), down, advertise and both. If you need to change the defaults and for example enable bidirectional CDP traffic use the esxcfg-vswitch command with the '-B' option followed by the desired mode.

# esxcfg-vswitch -B both MySwitch

Finally if you have a virtual switch which is not used anymore you can remove using the '-d' option of the esxcfg-vswitch command.

# esxcfg-vswitch -d MySwitch

The esxcfg-vswitch command support a few other options which are not used very often. To see the complete list run the esxcfg-vswitch -h command on the ESX server console or consult its manual page for detailed information.

Managing vSwitches using vSphere client

Vmware also offers the vSphere utility to manage your virtual switches which is available only for Windows hosts. If you do not have it already installed, open your favorite browser and type the IP address or the hostname of the ESX server and on the main page click the Download vSphere client to download it to your hard drive. Launch the setup and follow the instructions on the screen to complete the installation. If all went fine open the vSphere client and a dialog box like the one below will appear.

vSphere Client Login Dialog

Type the IP address of the ESX host, the username and the password you use to administer the server. Once you are logged in let's proceed in adding a new virtual switch using the following procedure:

  1. Click the ESX hostname in the inventory panel on the left, select the Configuration tab in the right window pane and then select Networking from the Hardware menu list..
  2. Next click the Add Networking link to start the Add Network Wizard.
  3. Add Network Wizard

  4. Choose the default option, "Virtual Machine" and click Next.
  5. Add Network Wizard

  6. Select "Create a virtual switch" option and if needed assign one or more physical adapters from the list depending on your configuration and press Next.
  7. Create a virtual switch

  8. In the Connection Settings dialog box type the name of the virtual machine port group in the Network Label text box and if necessary specify a VLAN ID between 1 and 4094 in the VLAN ID text box. Then click Next.
  9. Portgroup Properties

  10. Click Next to review the virtual switch configuration, and then click Finish. The new vSwitch will now be available for use and it will appear under the Networking section below the main vSwitch.
  11. Virtual Switch display

  12. Further if you need to configure some features of the newly create vSwitch click on the Properties... link near the virtual switch name which will open the vSwitch Properties dialog box.
  13. Virtual Switch Properties Dialog Box

  14. Here you can manage your virtual switch properties like security, traffic shaping, NIC teaming etc. You can change the number of ports, add supplemental portgroups, add network adapters for redundancy. Feel free to explore all the options available.
  15. If you need to delete a virtual switch from your configuration press the Remove... link near the vSwitch name.

Conclusion

Since networking is a crucial aspect of the ESX virtual environment, virtual switches play an important role on managing virtual networks and provide an unprecedented level of control while simplifying deployment, management, and troubleshooting.

Share this post

Last Updated on Friday, 19 August 2011 21:15
 

Comments  

 
0 #1 bobby 2011-12-30 21:24
Hello there, nice article.

Is that a typo here?? it should be 'created with 40 ports' not 64 ??

"If you specify for example 40 the switch will be created with 64 ports"


TIA
Quote
 

Add comment


Security code
Refresh

Copyright © 2011 Ciobanu Cristian - www.cioby.ro