Bridge Networking2009/06/13 |
[1] | Configure Bridge Networking for GuestOS. |
[root@dlp ~]# vi /etc/qemu-ifup
#!/bin/sh ME=$(basename $0) ifext=${ME#qemu-ifup-} case $ifext in qemu-ifup) ifname=eth0;; *) ifname=$ifext;; esac echo "Executing /etc/$ME" echo "Bringing up $1 for bridged mode..." /sbin/ifconfig $1 0.0.0.0 promisc up echo "Adding $1 to ${ifname}..." /usr/sbin/brctl addif $ifname $1 sleep 2 [root@dlp ~]# vi /etc/qemu-ifdown
#!/bin/sh set_ifname () { [ -e /sys/class/net/$1 ] || return ifname=$(cat /sys/class/net/$1/brport/bridge/uevent \ |grep ^INTERFACE |cut -d '=' -f 2) } ME=$(basename $0) set_ifname $1 echo "Executing /etc/$ME" if [ -z "$ifname" ]; then echo "Can not detect target bridge name" exit 1 fi echo "Removing $1 from ${ifname}..." /usr/sbin/brctl delif $ifname $1 echo "Shutting down $1 ..." /sbin/ifconfig $1 down sleep 2 [root@dlp ~]# chmod 755 /etc/qemu-* [root@dlp ~]# ln -s /etc/qemu-ifup /var/kvm/qemu-ifup-br0 [root@dlp ~]# ln -s /etc/qemu-ifdown /var/kvm/qemu-ifdown-br0
|
[2] | Start Guest like below. |
[root@dlp ~]# cd /var/kvm
[root@dlp kvm]# qemu-kvm -m 512 -hda www.img -net nic -net tap,ifname=tap,script=qemu-ifup-br0,downscript=qemu-ifdown-br0 -daemonize |
[3] | This example is that HostOS has 192.168.0.20, GuestOS has 192.168.0.21. |
[4] | Ping to Gateway from Guest and make sure bridge networking works normally like below. |
Sponsored Link |