Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 19 Jun 2007 07:49:33 +0200 (CEST)
From:      Per Hedeland <per@hedeland.org>
To:        ulrich@pukruppa.net
Cc:        freebsd-emulation@freebsd.org
Subject:   Re: Virtual network with qemu
Message-ID:  <200706190549.l5J5nXcP070584@pluto.hedeland.org>
In-Reply-To: <20070619053536.Y9390@small>

next in thread | previous in thread | raw e-mail | index | archive | help
"P.U.Kruppa" <ulrich@pukruppa.net> wrote:
>
>On Mon, 18 Jun 2007, Per Hedeland wrote:
>
>> "P.U.Kruppa" <ulrich@pukruppa.net> wrote:
>>>
>>> When now I try to connect the second virtual box, it will "steal"
>>> the first box's network connection.
>>
>> You need to give them individual mac addresses via the 'macaddr'
>> parameter to '-net nic'. I.e one of them can have the default
>> (52:54:00:12:34:56) but not more than one.:-) See e.g.
>Yes, but something goes wrong in my procedure:
>
># kldload aio kqemu if_tap bridge
># sysctl net.link.ether.bridge_cfg=rl0,tap0
># sysctl net.link.ether.bridge.enable=1
># qemu-system-x86_64 -hda Win2k.img -m 512 -localtime \
>   -net tap -net nic
># qemu-system-x86_64 -hda FreeBSD.img -m 512 -localtime -net tap 
>-net nic,52:54:00:12:34:57
>The latter will start the virtual FreeBSD box, but without a 
>working network (nothing can be ping'ed, not even the host).

OK - the second qemu will use tap1, so you need to add that to the
bridge_cfg sysctl when you use that method (I hope you didn't also
forget to mention that you already do that:-). Could be done in the
qemu-ifup script I guess, but it's a bit hairy. If you're running 6.x or
later, I definitely recommend using the ifconfig-based way of managing
the bridge instead (AFAIK the sysctl-based one is gone in CURRENT) - see
other posts in the thread I pointed you to.

>What kind of qemu-ifup do you use?

Per above I'm using the ifconfig-based method (on 6.1-RELEASE) - I use
this in rc.conf for the initial setup of the bridge:

cloned_interfaces="bridge0"
ifconfig_bridge0="addm bge0 up"

- this creates the bridge and adds the physical interface to it. You can
of course do it "manually" with

ifconfig bridge0 create
ifconfig bridge0 addm bge0 up

(you'd use rl0 instead of bge0 of course) - and then my qemu-ifup ups
the tap device and adds it to the bridge (if needed):

#!/bin/sh
sudo /sbin/ifconfig $1 up
case "`ifconfig bridge0`" in
    *" $1 "*) ;;      # already in the bridge 
    *) sudo /sbin/ifconfig bridge0 addm $1 ;;
esac

This works to bridge any number of qemus together (I've had as many as
five running concurrently).

--Per Hedeland




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200706190549.l5J5nXcP070584>