As the root user let's install some packages:
yum -y install wget openssl-devel gcc make python-devel openssl-devel kernel-devel graphviz kernel-debug-devel autoconf automake rpm-build redhat-rpm-config libtool python-twisted-core python-zope-interface PyQt4 desktop-file-utils libcap-ng-devel groff checkpolicy selinux-policy-devel
Add a new user and switch to that user:
adduser ovs
su - ovs
Download source code and prepare the build environmen.
mkdir -p ~/rpmbuild/SOURCES
wget http://openvswitch.org/releases/openvswitch-2.5.4.tar.gz
cp openvswitch-2.5.4.tar.gz ~/rpmbuild/SOURCES/
tar xfz openvswitch-2.5.4.tar.gz
Build the RPM package (no testing) and exit.
rpmbuild -bb --nocheck openvswitch-2.5.4/rhel/openvswitch-fedora.spec
exit
As root, we'll install the RPM package.
yum localinstall /home/ovs/rpmbuild/RPMS/x86_64/openvswitch-2.5.4-1.el7.centos.x86_64.rpm -y
Finally start the openvswitch service and check that it's running.
systemctl start openvswitch.service
systemctl is-active openvswitch
active --> Ok
Make openvswitch service to start at boot time:
systemctl enable openvswitch
Let's check that the command-line tools are ready:
ovs-vsctl -V
ovs-vsctl (Open vSwitch) 2.5.4
Compiled Apr 6 2017 13:07:27
DB Schema 7.12.1
Creamos o bridge OVSBrige e o porto correspondente
ovs-vsctl add-br OVSBridge
ovs-vsctl set port OVSBridge
systemctl stop NetworkManager
systemctl disable NetworkManager
Configuramos a interface física deste xeito:
DEVICE=eth0
ONBOOT=yes
DEVICETYPE=ovs
TYPE=OVSPort
OVS_BRIDGE=OVSBridge
BOOTPROTO=none
HOTPLUG=no
E configuramos a interfaz do openvswitch deste outro:
DEVICE=OVSBridge
ONBOOT=yes
DEVICETYPE=ovs
TYPE=OVSBridge
BOOTPROTO=static
IPADDR=91.121.85.142
NETMASK=255.255.255.0
GATEWAY=91.121.85.254
DNS1=80.80.80.80
DEFROUTE=yes
HOTPLUG=no
IPADDR1=192.168.0.100
NETMASK1=255.255.255.0
Facemos reboot da máquina para que arranque coa nova configuración
con virsh edit cambiamos a configuración da rede da máquina para que
arranque con openvswitch. Onde había algo así:
<interface type='bridge'>
<mac address='52:54:00:5a:2a:0a'/>
<source bridge='virbr0'/>
<model type='rtl8139'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03'
function='0x0'/>
</interface>
Quedaría isto:
<interface type='bridge'>
<source bridge='OVSBridge'/>
<virtualport type='openvswitch'>
</virtualport>
<model type='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03'
function='0x0'/>
</interface>
iptables:
Agora hai que esquecerse das reglas que crea o libvirt e crealas pola
nosa conta
#Masquerade do openvswitch
iptables --table nat -A POSTROUTING -s 192.168.0.0/24 --out-interface
OVSBridge -j MASQUERADE
##forwarding a diferentes servizos
iptables -t nat -A PREROUTING -i OVSBridge -p tcp --dport 80 ! -s
192.168.0.0/24 -j DNAT --to-destination 192.168.0.3:80
iptables -t nat -A PREROUTING -i OVSBridge -p udp --dport 53 ! -s
192.168.0.0/24 -j DNAT --to-destination 192.168.0.3:53
iptables -t nat -A PREROUTING -i OVSBridge -p tcp --dport 53 ! -s
192.168.0.0/24 -j DNAT --to-destination 192.168.0.3:53
##só permitimos o vnc dende a rede local
iptables -A INPUT -p tcp -s 127.0.0.1 -dport 5900:5920 -j ACCEPT
iptables -A INPUT -p tcp ! -s 192.168.0.0/24 --dport 5900:5920 -j DROP
Nota: a partir de agora se se crea unha nova máquina con virt-install
habería que creala xa indicando que a interface é do tipo bridge,
que o source bridge é OVSBridge e o virtualport do tipo openvswitch,
tamén está ben indicarlle que o model é virtio.
Se editamos unha máquina xa existente, é posible que o nome da interfaz
física cambie, polo que hai que editar a súa configuración de rede
para que tome o nome da interfaz correcta, por exemplo que antes fose
ens3 e agora eth0. Ademáis haberá que poñela na reda do openvswitch,
neste caso a 192.168.0.0/24 e indicar que o gateway é a ip do bridge,
neste caso 192.168.0.100
Completando a maravillosa información de Francisco Freire III o comando para facer unha instalación con virt-install podería ser algo tal que así:
virt-install --name web --ram 1024 --disk path=./web.qcow2 --vcpus 2 --os-type linux --os-variant generic --network bridge:OVSBridge,model=virtio,virtualport_type=openvswitch --graphics none --console pty,target_type=serial --location 'http://ftp.nl.debian.org/debian/dists/Debian9.4/main/installer-amd64/' --extra-args 'console=ttyS0,115200n8 serial'