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.
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.
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!
# Copyright (C) 2006 OpenWrt.org
config interface loopback
option ifname lo
option proto static
option ipaddr 127.0.0.1
option netmask 255.0.0.0
config interface wan
option ifname eth0
option proto dhcp
config interface lan
option ifname eth1
option proto static
option ipaddr 192.168.1.240
option netmask 255.255.255.0
Next, we install the ip package and quagga with bgp support.
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".
telnet localhost 2601 # for quagga
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".