1、环境准备
完成ovs安装
参考: Ubuntu 16.04 源码安装 openVswitch 2.10.0_品学楼A107-CSDN博客_ubuntu 安装openvswitch
2、准备环境结构图
3、创建网桥br-int 和 namespace
ovs-vsctl add-br br-int
ip netns add ns01
ip netns add ns02
ip netns add router-ns1
4、创建veth对口,连接网桥和namespace
1)创建veth口
ip link add veth01 type veth peer name veth02
ip link add veth03 type veth peer name veth04
ip link add veth05 type veth peer name veth06
ip link add veth07 type veth peer name veth08
2)连接namespace
ip link set veth01 netns ns01
ip link set veth03 netns router-ns1
ip link set veth05 netns router-ns1
ip link set veth07 netns ns02
3)连接网桥并启用端口
ovs-vsctl add-port br-int veth02
ifconfig veth02 up
ovs-vsctl add-port br-int veth04
ifconfig veth04 up
ovs-vsctl add-port br-int veth06
ifconfig veth06 up
5、配置namespace里的端口地址
ip netns exec ns01 ifconfig veth01 192.168.10.100/24 up
ip netns exec router-ns1 ifconfig veth03 192.168.10.1/24 up
ip netns exec router-ns1 ifconfig veth05 192.168.11.1/24 up
ip netns exec ns02 ifconfig veth07 192.168.11.110/24 up
6、配置router转发
ip netns exec router-ns1 sysctl -w net.ipv4.ip_forward=1
7、设置br-int网桥内部vlan隔离
ovs-vsctl set Port veth02 tag=3
ovs-vsctl set Port veth04 tag=3
ovs-vsctl set Port veth06 tag=4
ovs-vsctl set Port veth08 tag=4
8、结果
1)ping结果
2)网桥信息
tag:access口,内部的vlan值,同一vlan的网口数据进行转发
3) router信息
通过直连路由转发