Bridge Networking2010/06/10 |
[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 ..." /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. Generate random MAC address with following command and use it for "macaddr=xxx" # echo $(echo -n DE:AD:BE:EF ; for i in `seq 1 2` ;do echo -n `echo ":$RANDOM" | cut -n -c -3` ;done) |
[root@dlp ~]# cd /var/kvm
[root@dlp kvm]# qemu-kvm \ -smp 2 -m 512 -hda www.img \ -net nic,macaddr=52:54:00:12:34:56 \ -net tap,ifname=tap0,script=qemu-ifup-br0,downscript=qemu-ifdown-br0 \ -daemonize # -smp [virtual CPUs] # -m [amount of memory] # -net nic,macaddr=(MAC address) # -hda [virtual disk] # -daemonize [=make it daemon] # -nographic [=add it if you don't need graphics] |
[3] | This example is that HostOS has 10.0.0.30, GuestOS has 10.0.0.31. |
[4] | Ping to Gateway from Guest and make sure bridge networking works normally like below. |
Sponsored Link |
|