Qemu on FreeBSD 7

This article describes how to get Qemu running on FreeBSD 7.0 using network address translation (NAT). I'll assume bge0 as external network interface; replace it with your interface (e.g. re0 or wpi0). Using NAT is actually the only way to get internet connectivity via a wireless network from the guests. I'll use 192.168.3.0/24 as a local network for all qemu instances and run the NAT gateway and DNS server on 192.168.3.1.

Installing Qemu

Install the ports qemu and kqemu-kmod from /usr/ports/emulators. Don't forget to configure the qemu port with the kqemu kernel module accelerator, otherwise performance will not be optimal.

Host Configuration

To /boot/loader.conf add:

aio_load="YES"
kqemu_load="YES"

To /etc/rc.conf add:

cloned_interfaces="tap0"
ifconfig_tap0="inet 192.168.3.1 netmask 255.255.255.0 up"
gateway_enable="YES"
firewall_enable="YES"
firewall_type="OPEN"
natd_enable="YES"
natd_interface="bge0"
natd_flags="-same_ports"
named_enable="YES"
pf_enable="NO"

To /etc/sysctl.conf add:

net.link.tap.user_open=1

To /etc/devfs.rules add (also make sure that the user running qemu is part of group wheel):

add path 'tap*' mode 660

To /etc/namedb/named.conf add:

listen-on { 192.168.3.1; };

Now reboot.

Starting Qemu

Take a look at the man page for qemu for more options. For example to boot a DragonFly ISO image use:

qemu -m 256 -localtime -cdrom LATEST-Devel.iso \
     -net nic -net tap,ifname=tap0,script=no

For Windows XP, I prefer:

qemu -m 512 -localtime -usb -std-vga -hda $IMG \
     -soundhw es1370 \
     -name WindowsXP \
     -net nic -net tap,ifname=tap0,script=no

The -snapshot option is also very useful, especially for Windows.

Configuring the Guest

Once your guest system is up and running you have to configure it's network settings, so that you can connect to the internet. In case of BSD add the following two lines to /etc/rc.conf:

defaultrouter="192.168.3.1"
ifconfig_ed0="inet 192.168.3.2"

And for /etc/resolv.conf use:

nameserver 192.168.3.1