VirtualBox on FreeBSD cheat sheet
Network configuration with host bridge and bridged guest networking (FreeBSD host)
It appears that there is a problem with bridged guest networking when the interface you want to bridge to on the host is an if_bridge(4) interface. It doesn't seem to work with either the bridge interface, a physical interface or a vlan(4) interface.
What does work is to use a tap(4) interface for the VM. Unfortunately, VirtualBox requires exclusive use of the tap interface per VM, so you need to set up one for each VM.
Add all the required tap(4) interfaces to rc.conf(5):
cloned_interfaces="bridge0 tap0 tap1" ifconfig_bridge0="ether 02:00:00:00:00:01 addm tap0 addm tap1 addm em0"
Add these two lines to sysctl.conf(5):
net.link.tap.user_open=1 net.link.tap.up_on_open=1
The first enables non-root processes to open the tap interface, the seconds ifconfig up's the interface when the tap device is opened.
Then, add a rule to devfs.rules(5) to make the device node accessible to users running VirtualBox.
[diesel=100] add path tap* group wheel mode 660
(In rc.conf, I have devfs_system_ruleset="diesel", and my user is a member of the wheel group.)
Finally, configure your VM to use this interface:
$ VBoxManage modifyvm Ubuntu --nic1 bridged $ VBoxManage modifyvm Ubuntu --bridgeadapter1 tap1
I haven't tried renamed interfaces, but that might be worthwile to make it easier to remember which interface belongs to which VM.
Serial console (*nix host)
It is often easier to attach a terminal to the serial console of the guest than to connect via VNC.
Configure the VM:
$ VBoxManage modifyvm FreeBSD-9-mini --uart1 0x3f8 4 $ VBoxManage modifyvm FreeBSD-9-mini --uartmode1 server /tmp/FreeBSD-9-mini
Once the VM is running, you can connect to the console using socat:
$ socat UNIX-CONNECT:/tmp/FreeBSD-9-mini STDIO,raw,echo=0
For FreeBSD to offer (and prefer) the serial console, create a file /boot.config in the guest:
# echo -DhS115200 >/boot.config
This enables the dual console capability, and prefers the serial over the video console.
Patch for proper handling of VNC on IPv6-enabled machines (FreeBSD host)
PR #174976 has a patch to enable proper configuration of libvncserver when it's compiled with IPv6 support; the stock VirtualBox does not properly deal with this case, and leaves the IPv6 port number set to it's default value of 5900. This in turn means that you can only enable VNC on one of the VMs, as each subsequent one will fail to start up.
The following variables influence the selection of addresses and port numbers:
$ VBoxManage modifyvm Ubuntu --vrdeport 5902 $ VBoxManage modifyvm Ubuntu --vrdeproperty VNCPort4=5902 $ VBoxManage modifyvm Ubuntu --vrdeproperty VNCPort6=5902 $ VBoxManage modifyvm Ubuntu --vrdeproperty VNCAddress4=0.0.0.0 $ VBoxManage modifyvm Ubuntu --vrdeproperty VNCAddress6=::
Both VNCPort4 or VNCPort6 default to the port number set by --vrdeport; if that is unset or at it's default value of 3389, the extension will try to automatically determine an available port number when the VM start.
VNCAddress4 and VNCAddrees6 default to INADDR_ANY and IN6ADDR_ANY_INIT, respectively, so libvncserver will listen on all host addresses.
See VBoxVNC.cpp source code for details.