How to set up openwrt on Virtual Box for a network lab

At the DHBW our professor asked us to setup a bgp lab scenario with quagga. Every student was supposed to run his own bgp router on his laptop and initiate bgp sessions with other students via a switch that our professor provided.
My team and I decided to use OpenWrt on a virtual machine and run quagga, an open source software routing daemon. The setup was not as trivial for most of the other students, as it was for me. So here is a brief summary of what we did to get quagga working.

First of all, you need to download VirtualBox and the OpenWrt VDI-Image.

Then, create a new "Linux 2.6" virtual machine. Don't attach a boot hard disk to it, yet.
Open the settings menu of the newly created virtual machine, and deactivate USB and audio support. Activate a serial console. Delete the CD-drive and the sata-controller and attach the OpenWrt VDI-Image to the ide-controller.

I attached two network adapters to the virtual machine and configured the first adapter to use "NAT". This is very useful, because it allows you to download additional OpenWrt software packages via the internet connection of the host system.
The second network adapter was set up as a bridge connected to the ethernet adapter of our host system, which itself could then be connected to the lab network switch.
Please Note: You can not use the virtio network driver with OpenWrt, which might give you better performance. Performance, that you probably won't need it in a lab scenario anyway.

Now it's time to lauch your new OpenWrt instance.
You can leave the virtual machine with the right ctrl-key.
Note, that OpenWrt uses the us keyboard layout.

Hint: For a ":" you have to press the "ö" key on a German keyboard. "/" is on "-", "-" on "ß".

Once connected to your new virtual machine, you should set a root password. This allows you to access your machine via ssh.

  1. passwd

After that, we deactivate dnsmasq and the firewall. dnsmasq is a lightweight dns and dhcp server, i.e. something that only causes trouble in a lab. The firewall also is not necessary and only causes trouble. It is vital in a production environment, though.

  1. /etc/init.d/dnsmasq stop
  2. /etc/init.d/dnsmasq disable
  3. /etc/init.d/firewall stop
  4. /etc/init.d/firewall disable

Then, we change the network settings.
eth0 is connected to the VirtualBox NAT and should request an ip via dhcp.
eth1 is our bridged network and should get a static ip. Gotcha: Watch the interface names!

  1. vim /etc/config/network
  2. # Copyright (C) 2006 OpenWrt.org
  3.  
  4. config interface loopback
  5.         option ifname   lo
  6.         option proto    static
  7.         option ipaddr   127.0.0.1
  8.         option netmask  255.0.0.0
  9.  
  10. config interface wan
  11.         option ifname   eth0
  12.         option proto    dhcp
  13.  
  14. config interface lan
  15.         option ifname   eth1
  16.         option proto    static
  17.         option ipaddr   192.168.1.240
  18.         option netmask  255.255.255.0

Next, we install the ip package and quagga with bgp support.

  1. opkg update
  2. opkg install ip quagga quagga-libzebra quagga-bgpd

For quagga to work correctly, we have to delete the "." after "localhost" in /etc/hosts.

We can then start quagga and connect via telnet. The default passwort is "zebra".

  1. /etc/init.d/quagga start
  2. telnet localhost 2601 # for quagga
  3. telnet localhost 2605 # for bgpd

To access your virtal machine via putty from your host system, just add an ip to your host's bridged nic and allow the ip range in /etc/quagga/zebra.conf and /etc/quagga/bgpd.conf by changing "access-list vty permit 127.0.0.0/8" to "access-list vty permit any".