Open vSwitch on VirtualBox

Open vSwitch on VirtualBox

Open Vswitch Lab

Open vSwitch on VirtualBox

Here is a quick tutorial for installing Open vSwitch on VirtualBox. VirtualBox is an open source virtualization project from Oracle. It is supported on Windows, Mac, BSD and Linux to name a few. It has a nice GUI for VM management out of the box. Open vSwitch is an open source vSwitch from Martin Casado, Ben Pfaff and a whole crew of awesome. If you are here, OVS probably doesn’t require anymore explanation, learn it, love it.

Install VirtualBox

Install VirtualBox from the VirtualBox repository.

Install Open vSwitch from repo

Install Open vSwitch from Package. This is easiest for those not familiar with compiling from source or just need basic functionality rather than the latest features.

Open vSwitch Install from Source

Install dependencies and install from source on Ubuntu Linux.

Create Open vSwitch bridge and interfaces

To setup the virtual interfaces use Tuntap. Tuntap sets up a emulates an L2 interface. That interface will show up in the interface as a physical interface.

Open vSwitch VirtualBox

Spin up VirtualBox instances with Open vSwitch Interfaces

For testing Open vSwitch or any other hypervisor testing, I highly recommend this Linux image linux-0.2.img. It only takes a couple of MB of memory. It is perfect for nested hypervisor testing.

Open vSwitch VM

Connect the Open vSwitch bridge to the physical network

You can put the following into a text file and give it execute permissions with “chmod +x filename” and then run it “./filename”. If your network settings are right it should flip the IP to the bridge and not cut you off. Keyword “should” so have a way to get to the box if you cut yourself off. What is happening here is you are placing both the virtual interface “vnet0” and the physical Nic “eth0” into the same bridge “br0”. You can think of a bridge as a logical grouping of virtual and physical interface much like a locally significant VLAN without the 0x8100 Ethertype framing and tag.

Download your test image. If using the Linux-0.2.img it needs to be converted to vdi first using the VBoxManage utility included with the VirtualBox binary.

  • Create a new Virtualbox instance. Choose the linux-0.2.vdi (must duplicate the VDI or else all meta-data is the same and Vbox wont load the IMG). Do this as a regular user or else you will get permissions error.
  • Choose “use existing virtual HD”
  • Ignore “failed to get USB blah”.
  • If you get “dpif_linux|ERR|Generic Netlink family ‘ovs_datapath’ does not exist. The Open vSwitch kernel module is probably not loaded.” Make sure you are adding the Open vSwitch kernel module e.g insmod datapath/linux/openvswitch.ko.
  • Under interfaces set to “bridged interface” and choose the port on the appropriate bridge. E.g Bridge1-p2, br-head-p1 etc. Make sure it is a port and not a bridge.
  • You can go really low on memory, I tend to just use 32mb but you can go less.

Thanks for stopping by.

About the Author

Brent SalisburyI have over 15 years of experience wearing various hats from, network engineer, architect, devops and software engineer. I currently have the pleasure of working at the company that develops my favorite software I have ever used, Docker. My comments here are my personal thoughts and opinions. More at Brent's BioView all posts by Brent Salisbury →

  1. Calin C.Calin C.03-14-2013

    Nice writing, I’ll give it a try on upcoming weekend!

  2. Raj MurtintyRaj Murtinty03-16-2013

    Brent , it is unclear how can I load the vSwitch on OS X Mountain Lion . I have virtualbox installed on it and have Fedora/Ubuntu running as VM on VirtualBox

    • Brent SalisburyBrent Salisbury03-21-2013

      Hi Raj, you would install (binary) or compile (source) Open vSwitch on the Ubuntu guest host running inside nested inside the Ubuntu host.

      -So on your mac install VMFusion or Virtualbox and spin up an Ubuntu host.
      -On the Ubuntu host, install OVS and VirtualBox.
      -For performance you would run Ubuntu natively on the bare metal pc/server.

      Lemme know if that doesnt make sense.


  3. DanielDaniel03-17-2013

    Hello! Thank for this note. But I have just a question, Can we do a ping to an external network (to internet, for example “ping”)? If it isn’t possible, how could I do it?

    Thank you.

    • Brent SalisburyBrent Salisbury03-21-2013

      Hi Daniel,

      Couple of things to check.

      1. Make sure you added eth0 to br0 (or whatever you named the OVS bridge with “ovs-vsctl add-br br0”). To add eth0 to the br0 bridge run “ovs-vsctl add-port br0 eth0”. vnet0 needs to also be in that same bridge with “ovs-vsctl add-port br0 vnet0”
      2. zero out eth0. “ifconfig eth0 0” (warning that will cut you off, pop it in a bash script if remote).
      3. Add the eth0 ip to br0. “ifconfig br0 netmask” < -insert your IPs. 4. Add a default route/gateway. “route add default gw br0” <-insert your default gw. 5. Do a “route -n” and check for the route using br0. If there is one still with eth0 run “route del default gw eth0” to delete the old eth0 route. 6. Try pinging your default gateway to make sure you have local connectivity. 7. “ifconfig -a”

  4. AviAvi04-25-2013

    Hello Brent,
    Thank you very much for this useful guide.
    I was trying to follow it and install a ovs with several VMs in virtual box.
    I wasn’t sure if I should define a new virtual interface for each VM, and if so should it also be in the same bridge interface?
    Thank you,

  5. Brent SalisburyBrent Salisbury04-28-2013

    Hi Avi,

    You got it, new vPort needs be created and added to the single bridge. New bridges would be if you need seperate datapaths. Think of the different bridges as totally seperate physical switches. Like a VDC on a Cisco Nexus or logical-system in Junos on Juniper platforms.

    In the following example:
    Bridge == Bridge1
    Portnames == Bridge1p1 && Bridge1p2

    ovs-vsctl add-br Bridge1
    ip tuntap add mode tap Bridge1p1
    ip link set Bridge1p1 up
    ip link
    ovs-vsctl add-port Bridge1 Bridge1p1

    ovs-vsctl add-br Bridge1
    ip tuntap add mode tap Bridge1p2
    ip link set Bridge1p2 up
    ip link
    ovs-vsctl add-port Bridge1 Bridge1p2

  6. John DeatherageJohn Deatherage05-04-2013

    This article was really the kick in the teeth to run Ubuntu as my primary OS on every desktop+laptop I use. Everything I have is either Ubuntu, or a bare metal hypervisor of some sort. Too much stuff to test!

  7. Brad SmithBrad Smith06-07-2013

    Could you explain a little more what you’re doing with the linux-0.2.vdi image? My guess is running in the VBox that’s running in Ubuntu with OVS on the linux-0.2 image… but I couldn’t follow you on how to do this…

    Thanks for the writeup!


    • Brent SalisburyBrent Salisbury06-10-2013

      Hi Brad, it’s nice to use as a test VM host if labbing or testing code up on a laptop/desktop. You can spin up multiple guest VMs on very little hardware to test connectivity and what not.

      Lemme know if I missed your question.


  8. A.MedhatA.Medhat08-26-2013

    Hallo Brent,
    I have 5 VMs on the Virtual box, one Floodlight controller, 2 Openvswitches and 2 host.
    the network is as follows:

    the 2 switches connected together and connected to the controller and each switch is connected to one Host. the interfaces using for every VM is -internal interface- type. The openvswitches are connected together with the hosts and the controller. There is no problem in that. The problem is here that when I ping from one host to other, there is no pinging. So What is the problem ?

    Thank you in advance for your support.

    • Brent SalisburyBrent Salisbury09-08-2013

      Hey bud, sorry for the delay. If you are still having issues ping the thread and I will take a look.

  9. Dmitri Ch.Dmitri Ch.08-30-2013

    Thanks for the useful post.
    For OVS to work in a VM, do you need to allow promisc mode on the interface in VM’s settings (in VBox, Network->[Adapter]->Advanced->Promisc mode ) ?

    • Brent SalisburyBrent Salisbury09-08-2013

      Hi Dmitri, good question. Ive not noticed any issues before other then multinodes in one case that I remember but its been a while and I dont remember the details. I leave it in promiscuous fwiw.


  10. Shashikant NigamShashikant Nigam10-03-2013

    Hello Brent,
    Nice informaton, I have a request that can you please give me information about installation of openvswitch-1.11.0 on suse 11 sp 2 running on virtual box.

  11. Anu MAnu M10-23-2013

    Hi Brent!

    Your articles are very interesting, I am hooked to your blogs most of the time:-)

    I have a doubt regarding bringing up each of the Virtual Box instances. should they necessarily be in “use existing virtual HD” ? I have created the VBox instances using new HD spaces, and now I am having the issue of not being able to ping between each of the machines.

    The structure of my network: I have one OVS switch connected to Controller in the host. I have an OVS switch in two of my virtual Box instances (each of them have Ubuntu spun on them). I am unable to ping from the host to either of the virtual machines.

  12. Sunin.TSunin.T01-02-2014

    Nice, article and I had tried it.
    Do you have any idea for setup the VM (Xen Server) to use with external OVS such as Pica8, Cumulus for example.

    I’m looking for any solution like a VMWare with Cisco Nexus 1000v


  13. SandraSandra01-09-2014

    Hi Brent,

    Thanks for the tutorial. I’ve been trying to set up some host VMs for my network and I came across a problem with the linux-0.2.vdi
    When I try to generate a new VM with this image, I get the following error:

    VFS:Cannot open root device “300” or unknown-block(3,0)
    Please append a correct “root=” boot option
    Kernel panic – not syncing: VFS: Unable to mount root fs on unknown-block(3,0) Time: tsc clocksource has been installed.

    Have you ever come across something like this?
    Thank you very much.
    All the best,

  14. SandraSandra01-09-2014


  15. AdamsAdams02-03-2014

    Hi Brent,

    Good write up and very accessible.
    I have a question on how to connect two guest VMs to a single OVS instance and allow both to ping ?
    At any one time I can only manage to allow one VM to ping out, am I missing something here ?

    VM1 –> Tap1 —>
    ——-> |———————-|
    ——> | Ovsbr0 |
    VM2–> Tap2—>| | [eth0] |——>

    — i’ve blanked out eth0, ifconfig eth0 0, likewise ovsbr0 has no ip
    — they are all on the same subnet which has public IP (VM1 & VM2 have public IP)