Sunday, April 13, 2008

qemu networking fedora 8

Copy the following two files into /etc/

/etc/qemu-ifup

#!/bin/sh
# qemu-ifup
# script to bring up the tun device in QEMU in bridged mode
#
# This script bridges eth0 and tap0. First take eth0 down, then bring it up with IP 0.0.0.0
# if you do not use eth0 as the primary, change it to your interface name
ETHX=eth0
/sbin/ifdown ${ETHX}
/sbin/ifconfig ${ETHX} 0.0.0.0 up
#
# Bring up tap0 with IP 0.0.0.0, create bridge br0 and add interfaces ${ETHX} and tap0
#
/sbin/ifconfig tap0 0.0.0.0 promisc up
/usr/sbin/brctl addbr br0
/usr/sbin/brctl addif br0 ${ETHX}
/usr/sbin/brctl addif br0 tap0
#
# As we have only a single bridge and loops are not possible, turn spanning tree protocol off
#
/usr/sbin/brctl stp br0 off
#
# Bring up the bridge with IP 192.168.1.2 and add the default route
# Change this to your static IP if you want the linux OS to route when the Guest OS is bridged in
/sbin/ifconfig br0 10.160.221.163 up
/sbin/route add default gw 255.255.255.0
#stop firewalls
/sbin/service iptables stop

/etc/qemu-ifdown

#!/bin/sh
# qemu-ifdown
# Script to bring down and delete bridge br0 when QEMU exits
#
# Bring down eth0 and br0
# then run the eth0 up script which should restart the firestarter firewall and reconfig the normal ip onto eth0
# if you do not use eth0 as the primary, change it to your interface name
ETHX=eth0
/sbin/ifdown ${ETHX}
/sbin/ifdown br0
/sbin/ifconfig br0 down
#
# Delete the bridge
#
/usr/sbin/brctl delbr br0
#
# bring up eth0 in "normal" mode
#
/sbin/ifup ${ETHX}
#start firewalls again
/sbin/service iptables start
Make sure that the tun device is installed.
#~> lsmod | grep tun

to manually start qemu:

#~>qemu-kvm -localtime -net nic1 -net user1 -hda /home/dave/Public/winxp.img -hdb /home/dave/Public/winxp_disk2.img -m 256 -usb -usbdevice tablet -daemonize