From owner-freebsd-emulation@FreeBSD.ORG Fri Aug 21 14:05:55 2009 Return-Path: Delivered-To: freebsd-emulation@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BF4A3106568B for ; Fri, 21 Aug 2009 14:05:55 +0000 (UTC) (envelope-from freebsd-emulation@m.gmane.org) Received: from lo.gmane.org (lo.gmane.org [80.91.229.12]) by mx1.freebsd.org (Postfix) with ESMTP id 50EDF8FC63 for ; Fri, 21 Aug 2009 14:05:55 +0000 (UTC) Received: from list by lo.gmane.org with local (Exim 4.50) id 1MeUCv-0000PI-LI for freebsd-emulation@freebsd.org; Fri, 21 Aug 2009 15:31:05 +0200 Received: from 200.41.broadband11.iol.cz ([90.178.41.200]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 21 Aug 2009 15:31:05 +0200 Received: from gamato by 200.41.broadband11.iol.cz with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 21 Aug 2009 15:31:05 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: freebsd-emulation@freebsd.org From: martinko Date: Fri, 21 Aug 2009 15:30:42 +0200 Lines: 91 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 200.41.broadband11.iol.cz User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.8.1.18) Gecko/20081125 SeaMonkey/1.1.13 Sender: news Subject: Automagic bridged networking with QEMU (tap) X-BeenThere: freebsd-emulation@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Development of Emulators of other operating systems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 Aug 2009 14:05:55 -0000 Hallo list, I spent a good portion of yesterday trying to find out how to change from using user mode to bridged networking with QEMU on FreeBSD 7.2. As I found a few how-to's of differing quality and I couldn't manage to make it work for some time, I decided to share the final results of my journey with you as I believe it may save someone a few hours or hair. The proposed solution does not need any manual steps and is fully transparent to users (like user mode networking is). It does not even permanently bridge your real NIC, only when necessary, which is good because of some performance penalties when bridging. And you can run as many guests as you want and it's all set up automagically. :-) OK, enough words, here's what to do: /boot/loader.conf[.local]: if_bridge_load="YES" if_tap_load="YES" /etc/sysctl.conf: net.link.tap.up_on_open=1 net.link.tap.user_open=1 /etc/devfs.rules: [localrules=10] add path 'tap*' mode 0660 /etc/rc.conf[.local]: devfs_system_ruleset="localrules" kqemu_enable="YES" /usr/local/etc/qemu-ifup -- custom script /usr/local/etc/qemu-ifdown -- custom script --- /usr/local/etc/qemu-ifup #!/bin/sh # # /usr/local/etc/qemu-ifup : martinko [20-aug-2009] # IFNAME=re0 for BRIDGE in $(ifconfig -a | grep '^bridge' | cut -d: -f1) do if [ -n "$(ifconfig "$BRIDGE" | grep -w "member: $IFNAME")" ] then echo "${0##*/}: Adding $1 as a member of $BRIDGE" sudo /sbin/ifconfig "$BRIDGE" addm "$1" up exit fi done BRIDGE="$(sudo /sbin/ifconfig bridge create)" sudo /sbin/ifconfig "$BRIDGE" addm "$IFNAME" addm "$1" up echo "${0##*/}: Created $BRIDGE and added $1 as a member" --- /usr/local/etc/qemu-ifdown #!/bin/sh # # /usr/local/etc/qemu-ifdown : martinko [20-aug-2009] # for BRIDGE in $(ifconfig -a | grep '^bridge' | cut -d: -f1) do if [ -n "$(ifconfig "$BRIDGE" | grep -w "member: $1")" ] then if [ "$(ifconfig "$BRIDGE" | grep -c -w "member:")" -le 2 ] then echo "${0##*/}: Destroying $BRIDGE" sudo /sbin/ifconfig "$BRIDGE" destroy fi echo "${0##*/}: Destroying $1" sudo /sbin/ifconfig "$1" destroy fi done --- And that's all, folks! :) Enjoy and if you find a better solution please let me/us know. Cheers, Martin PS1: Of course change IFNAME in qemu-ifup according to your setup. PS2: You man want/need to change the group in devfs.rules as well.