Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save archerslaw/c68fa13964582095f620 to your computer and use it in GitHub Desktop.
Save archerslaw/c68fa13964582095f620 to your computer and use it in GitHub Desktop.
use the openvswitch tool to setup OVS network for KVM.
# yum install openvswitch -y
# systemctl start openvswitch.service | #service openvswitch start
# chkconfig openswitch on
# ovs-vsctl --help
Open vSwitch commands:
init initialize database, if not yet initialized
show print overview of database contents
emer-reset reset configuration to clean state
Bridge commands:
add-br BRIDGE create a new bridge named BRIDGE
add-br BRIDGE PARENT VLAN create new fake BRIDGE in PARENT on VLAN
del-br BRIDGE delete BRIDGE and all of its ports
list-br print the names of all the bridges
br-exists BRIDGE exit 2 if BRIDGE does not exist
br-to-vlan BRIDGE print the VLAN which BRIDGE is on
br-to-parent BRIDGE print the parent of BRIDGE
br-set-external-id BRIDGE KEY VALUE set KEY on BRIDGE to VALUE
br-set-external-id BRIDGE KEY unset KEY on BRIDGE
br-get-external-id BRIDGE KEY print value of KEY on BRIDGE
br-get-external-id BRIDGE list key-value pairs on BRIDGE
Port commands (a bond is considered to be a single port):
list-ports BRIDGE print the names of all the ports on BRIDGE
add-port BRIDGE PORT add network device PORT to BRIDGE
add-bond BRIDGE PORT IFACE... add bonded port PORT in BRIDGE from IFACES
del-port [BRIDGE] PORT delete PORT (which may be bonded) from BRIDGE
port-to-br PORT print name of bridge that contains PORT
# brctl show
# ifconfig switch down
# brctl delif switch eth0
# killall dhclient
OR:
rhel6# ifconfig switch down; brctl delif switch eth0; brctl delbr switch; service NetworkManager stop
rhel7# ifconfig switch down; brctl delif switch eth0; brctl delbr switch; systemctl disable NetworkManager.service
# ovs-vsctl add-br ovs0
# ovs-vsctl add-port ovs0 eth0
OR: the above two can in one single line
# ovs-vsctl add-br ovs0 -- add-port ovs0 eth0
# dhclient ovs0
[if bonded: # ovs-vsctl add-bond bond0 eth1 eth2 xxx]
# ovs-vsctl add-port ovs0 tap0
# ovs-vsctl add-port ovs0 tap1 tag=10
# ovs-vsctl add-port ovs0 tap2 tag=20
# ovs-vsctl -- add-port ovs0 vlan10 tag=10 \
-- set interface vlan10 type=internal
Setup guest network up/down script.
# cat /etc/ovs-ifup
#!/bin/sh
switch='ovs0'
/sbin/ifconfig $1 0.0.0.0 up
ovs-vsctl add-port ${switch} $1
#cat /etc/ovs-ifdown
#!/bin/sh
switch='ovs0'
/sbin/ifconfig $1 0.0.0.0 down
ovs-vsctl del-port ${switch} $1
# ovs-vsctl show
5c4e38c9-f83a-4515-9775-fc48e8f5f126
Bridge "ovs0"
Port "ovs0"
Interface "ovs0"
type: internal
Port "tap0"
Interface "tap0"
Port "eth0"
Interface "eth0"
ovs_version: "2.0.1"
# ovs-vsctl del-port tap0
# ovs-vsctl del-br ovs0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment