kvm use openvswitch

文章目錄

install openvswitch

1
2
yum install openvswitch
service openvswitch start

install tunctl for creating tun device

1
yum install tunctl

what’s tun and tap device

1
2
tun: short for "Tunnel" L3-device
tap: L2-device

create startup and shutdown script for ovs tap device

1
2
3
4
5
6
7
8
9
10
11
12
/opt/ovs-ifup
---------------------------------
switch='br0'
/sbin/ifconfig $1 0.0.0.0 up
ovs-vsctl add-port ${switch} $1
/opt/ovs-ifdown
switch='br0'
/sbin/ifconfig $1 0.0.0.0 down
ovs-vsctl del-port ${switch} $1

add a bridge and associate a physical nic to it

1
2
ovs-vsctl add-br br0
ovs-vsctl add-port br0 eth0

install a vm

1
2
3
# qemu-kvm -m 1024 -net nic,model=virtio -net tap,script=/opt/ovs-ifup,downscript=/opt/ovs-ifdown -drive file=test.img -cdrom CentOS-6.5-x86_64-minimal.iso -usb -usbdevice tablet -boot d -nographic -vnc :20
then use a vnc client to finish the installation

boot the vm

1
2
# qemu-kvm -m 1024 -drive file=/opt/work.img,if=virtio -net nic,model=virtio -net tap,script=/opt/ovs-ifup,downscript=/opt/ovs-ifdown -usb -usbdevice tablet -nographic -vnc :20
now we have a vm with a nic bridged to physical nic