Skip to content

Instantly share code, notes, and snippets.

@zarzen
Last active December 29, 2023 07:09
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save zarzen/5bc114dadb92c01c75b879af47c7e5cb to your computer and use it in GitHub Desktop.
Save zarzen/5bc114dadb92c01c75b879af47c7e5cb to your computer and use it in GitHub Desktop.
ovs example

install openvswitch 2.4

uninstall ovs-2.5

sudo apt autoremove  openvswitch-common openvswitch-switch-dpdk openvswitch-dbg openvswitch-pki openvswitch-ipsec openvswitch-switch openvswitch-switch-dpdk openvswitch-ipsec openvswitch-test openvswitch-testcontroller openvswitch-vtep

download source code

wget http://openvswitch.org/releases/openvswitch-2.4.0.tar.gz

unpack and compile

tar zxvf openvswitch-2.4.0.tar.gz
cd openvswitch-2.4.0
# install dependencies
apt-get install build-essential fakeroot
apt-get install
# check dependencies
dpkg-checkbuilddeps
# this may have problem
# fix it by modifying one rule in debian/rule file
# dh_shlibdeps -> dh_shlibdeps --dpkg-shlibdeps-params=--ignore-missing-info
fakeroot debian/rules binary
# previous command will produce deb binary for installation
# binary at parent folder of openvswitch source code
sudo dpkg -i openvswitch-common_2.4.0-1_amd64.deb
sudo dpkg -i openvswitch-switch_2.4.0-1_amd64.deb

Openvswitch installation on Ubuntu 16.04

# make sure all tools are installed.
sudo apt-get install openvswitch-common openvswitch-switch-dpdk openvswitch-dbg openvswitch-pki openvswitch-ipsec openvswitch-switch openvswitch-switch-dpdk openvswitch-ipsec openvswitch-test openvswitch-testcontroller openvswitch-vtep

Network configuration

# add bridge
sudo ovs-vsctl add-br br1
# create virtual nic
sudo ip tuntap add mode tap vnet0
# 
sudo ip link set vnet0 up
# add virtual nic to bridge
sudo ovs-vsctl add-port br1 vnet0
# start up bridge
sudo ifconfig br1 up

# confirm status
sudo ip link
ifconfig
# check bridge status

# config virtual switch ip
sudo ifconfig br1 172.16.1.1 netmask 255.255.255.0 up

# setup virtual machine:
Network -> Bridged Adapter -> vnet0 

# setup the ip address inside virtual machine
sudo ifconfig <interface-name> 172.16.1.2 netmask 255.255.255.0 up

# more than one virtual machine
# select the same bridged adapater as previously did.
Network -> Bridge Adapter -> vnet0
# but setup different ip address inside virtual machine
sudo ifconfig <interface-name> 172.16.1.3 netmask 255.255.255.0 up

Make the internal network can access the Internet

# see the current IP address hold by network interface
ifconfig 
ovs-vsctl add-port br1 <network interface>
ifconfig <network interface> 0
ifconfig br1 <IP network interface holds> netmask <netmask>

# add route 
route add default gw <xxx.xxx.xx.1> br1
@Bigbear325
Copy link

sudo /usr/share/openvswitch/scripts/ovs-ctl start

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment