pfSense router setup in VirtualBox

Posted in Tech on October 14th, 2010 by blakangel

I actually set up pfSense months ago and it’s been running flawlessly since then. pfSense is a router distribution of FreeBSD. I’ve always considered FreeBSD a robust and well-performing server platform, and want to see how well it performs as a router.
First I’ll give you a quick look at my current virtualbox test lab:

VirtualBox Lab Diagram

I’ve been a huge FreeBSD user/admin for years, both at work and at home and haven’t had the chance to take a look at a FreeBSD-based router/firewall platform.

So we start creating the vm (remember the last post I aliased VBoxManage to vboxmanage -q (for quiet) to make it easier):

vboxmanage createhd --filename /storage/bangel/vbox-disks/router2.vdi --size 2048 --format VDI --variant standard
vboxmanage createvm --name router2 --ostype FreeBSD --register

I know I created a 2gig disk, but the actual pfSense install only ended up requiring 230 MB for the base system and I gave it 128 Megs for swap. If you plan on installing additional software or features, the space could come in handy. For example, web proxy/cache or NIDS logging.

Next I’m going to assign RAM, a VRDP port, both IDE and SATA storage controllers, then attach my media. Remember that currently, virtual DVD drives can only be attached to IDE Controllers.

vboxmanage modifyvm router2 --memory 128 --vrdp on --vrdpport 3395
vboxmanage storagectl router2 --add sata --name "SATA Controller 1"
vboxmanage storageattach router2 --storagectl "SATA Controller 1" --port 0 --device 0 --type hdd --medium /storage/bangel/vbox-disks/router2.vdi
vboxmanage storagectl router2 --add ide --name "IDE Controller 1"
vboxmanage storageattach router2 --storagectl "IDE Controller 1" --port 0 --device 0 --type dvddrive --medium /storage/bangel/isos/pfSense-1.2.3-RELEASE-LiveCD-Installer.iso

Now I typo’d the last command about three times. Don’t be discouraged if you do the same thing or have to run ‘vboxmanage modifyvm’ and get the list of options. I still have to do that sometimes. It takes a lot of practice to become proficient with the virtualbox command line utilities.

So next let’s setup the network cards. When you create a new virtual machine, VBox defaults to a specific NIC depending on OS. For FreeBSD, we get the Intel(R) PRO/1000 Gigabit Ethernet adapter, which has a great driver and is well-supported. Here we setup the second NIC, set them to “intnet” and then give names to the two “intnets” . When you assign names to the internal network VBox creates virtual switches and “plugs in” your NICs. Notice that our two interfaces are plugged into different switches. Remember this is a router.

vboxmanage modifyvm router2 --nictype2 82540EM
vboxmanage modifyvm router2 --nic1 intnet
vboxmanage modifyvm router2 --nic2 intnet
vboxmanage modifyvm router2 --intnet1 internal-network
vboxmanage modifyvm router2 --intnet2 core-network

Make sure to run ‘vboxmanage showvminfo <yourvmname>” and note the NIC 1 and NIC 2 lines. Document the MAC addresses and which virtual switch (intnet) they are assigned to. Go ahead and start up the new VM to begin pfSense installation. I use ‘VBoxHeadless -s router2′ then connect via RDP. Make sure to set your LAN address to something on your network for now, the pfSense default firewall settings only allow access to the web interface from the LAN interface. After installation I added a pf rule to allow it from any interface; since this is all internal, there are no security concerns. I also enabled SSHD. All the normal commands from FreeBSD are available in console and I find it makes troubleshooting easier.

Once installation is complete, I shut off the VM and change remove the ISO from the boot list:

vboxmanage controlvm router2 poweroff
vboxmanage modifyvm router2 --boot2 none

Now we can make copies of the VDI file either manually or with VirtualBox’s clonehd function.

One Response to “pfSense router setup in VirtualBox”

  1. FreeBSD news and links (week 40) | FreeBSD - the unknown Giant Says:

    [...] 6. pfSense router setup in VirtualBox [...]

Leave a Reply