I’ve been using qemu lately to test kernel changes. In particular I’m using qemu-0.7.2 running x86 virtual machines on an amd64. This configuration seems to work really well, particularly once I remembered to “echo 1 >/proc/sys/kernel/sysrq” in the host OS’s rc.local (doh!)
Today I switched from using qemu’s user mode network stack to using the tun/tap interface with masquerading. To that end, my qemu startup script now looks like this:
#!/bin/bash # qemu.sh sudo bash -c 'echo 1024 > /proc/sys/dev/rtc/max-user-freq' #sudo modprobe kqemu qemu \ -kernel linux-2.6-qemu/arch/i386/boot/bzImage \ -append 'console=ttyS0 root=/dev/hda ro clock=pit' \ -hda root_fs.fc-4-base.pristine.20051026 \ -nographic \ -n $PWD/qemu-ifup \ "$@"
and qemu-ifup looks like this:
#!/usr/bin/sudo bash /sbin/ifconfig $1 172.20.0.1 iptables --table nat --flush iptables --table nat --append POSTROUTING \ --source 172.20.0.0/16 --destination ! 172.20.0.0/16 \ --jump MASQUERADE [[ -e /proc/sys/net/ipv4/ip_forward ]] && \ echo 1 > /proc/sys/net/ipv4/ip_forward
This gives me outgoing networking from the virtual machine, plus incoming networking from the host OS. The virtual OS uses 172.20.0.2 on its virtual adapter.