Open vSwitch on Gentoo – Setting Up Your First vSwitch
In my last post I outlined how to get Open vSwitch installed on Gentoo from source for version 1.11.0 as well as from portage using version 2.0.0. I also described how to associate Open vSwitch with with Xen based virtual machines. This guide will detail how to build your first virtual switch from scratch and create virtual switch ports associated with the virtual switch that persist upon a reboot of the host machine. The virtual ports can then be used with VirtualBox VMs and other generic applications that can make use of them.
If you followed my last post you should have Open vSwitch installed and the respective services running. You should also have created an initial bridge interface, this was called xenbr0 and was created with the following commands:
where enp4s0 is your physical interface that is bound to the bridge. This is necessary since this will be the “switch” port that “uplinks” the vSwitch to the rest of the physical network.
You should now be able to view the current bridge setup by using the following command:
Which should display output similar to this:
This shows that the bridge is created and has a single port attached to it labeled enp4s0 that is bound to the physical interface enp4s0.
At this point you should be fine if you were using this for a Xen based setup since the hotplug scripts provided with xen-tools will take care of the virtual interface setup for each VM. However if you want to use Open vSwitch with VirtualBox based VMs on a Gentoo host read on …
In order to create virtual switch ports that you can bind to your virtual machines a tun/tap interface must be created for each port that will be needed. So if you wish to create a 16 port switch 16 tap interfaces will be necessary. These interfaces can be added to the vSwitch as follows:
First verify that the tun module is loaded
If this does not run verify that you have tun compiled as a module in your kernel.
And that the tun module is set to load on boot up in /etc/conf.d/modules:
Next create the tap interfaces for each virtual switch port, in this example I will create an 8 port switch.
Now check that they were added:
Which should display:
This indicates that the virtual ports have been associated with the vSwitch xenbr0, however the interfaces still need to be created. In order to do this entries need to be made in /etc/conf.d/net that describes each tap interface and how they will be configured at bootup. In the case of these tap interfaces we want them to be brought up but not configured. So in /etc/conf.d/net add the following entries:
Notice how they are all set to “null” this indicates that on bootup they will not be assigned an IP address nor will they poll a DHCP server for an address.
Next create the device symlinks in /etc/init.d/ as you would for any other network interface so that they can be started on bootup:
Then add them to the default runlevel:
Now reboot the server and everything should start up correctly.
After the server comes back online verify that the new ports are all associated with the vSwitch.
Which should return output similar to this:
Finally fire up VirtualBox and create a new VM or go to the settings of an old VM and set the network interface to “bridged mode” and choose one of the new switch ports in the list. Fire up the VM and you should have a connection!