Qemu: bridging on FreeBSD 7.0-STABLE
Per Hedeland
per at hedeland.org
Sun Mar 9 11:46:26 UTC 2008
"Sam Fourman Jr." <sfourman at gmail.com> wrote:
>
>I am confused a bit,
>
>so what would I have to put in /etc/sysctl.conf so that qemu would
>have bridging for a user, automatically on bootup
>
>would I have to have a shell script of some sort? and would it not
>have to test if there already is a tap0?
>
>I have been trying to get this to work for awhile, if anyone has
>config files they could post I would very much appreciate it.
>
>esp if you could get multiple qemu's to bridge at once
Here's the setup I use:
0. In /boot/loader.conf:
if_tap_load="YES"
This may actually be redundant though, I haven't tried w/o it.
1. In /etc/sysctl.conf:
# Allow user open of tap device for qemu networking
net.link.tap.user_open=1
2. In /etc/devfs.rules:
[localrules=10]
# devfs starts before NIS, so need numerical uid here (if you use NIS)
add path 'tap*' user 1016
3. In /etc/rc.conf:
devfs_system_ruleset="localrules"
cloned_interfaces="bridge0"
ifconfig_bridge0="addm bge0 up"
I.e. this is one-time stuff, you can of course do it manually instead
when testing:
ifconfig bridge0 create
ifconfig bridge0 addm bge0 up
Use the name of your physical ethernet interface instead of "bge0",
of course.
4. /etc/qemu-ifup:
#!/bin/sh
sudo /sbin/ifconfig $1 up
case "`ifconfig bridge0`" in
*" $1 "*) ;; # already in the bridge
*) sudo /sbin/ifconfig bridge0 addm $1 ;;
esac
Finally, to run multiple qemus with bridged networking you *must* assign
them different MAC addresses via -net nic,macaddr=52:54:00:XX:XX:XX
(well, one of them can have the default of course). I just hardwire
them, but in an earlier discussion here, Bakul Shah posted a nice trick
to auto-generate the MAC address:
Right. I use a shell function to create a macaddress based on
directory of the image file. Something like:
macaddr() {
echo 52:54:0:$(echo $1|md5 |cut -c1-6|sed 's/\(..\)\(..\)/\1:\2:/')
}
qemu -net nic,macaddr=$(macaddr $(dirname $(realpath $1))) -hda $*
And invoke it as, for example,
my-qemu /usr/oszoo/plan9 ...
Incidentally that post can *not* be found by searching the
freebsd-emulation archives at freebsd.org, but there's always google...
--Per
More information about the freebsd-emulation
mailing list