1、openstack多租户实现IP逻辑资源复用示意图
实现隔离的方式是用network namespace 实现router 隔离。
如果没有router隔离,租户网络路由无法正常转发。
比如:
租户A 192.186.10.100 访问 192.186.11.110,因为有router-ns1隔离,才能转发到ns02。且router namspace和租户相对应。
假设没有 router-ns1 和 router-ns2,198.168.10.1和198.168.11.1直接暴露在host network,无法设置路由规则转发给正确的目的网口。
2、租户网络
租户A: 192.186.10.0/24 vlan 3; 192.186.11.0/24 vlan 4
租户B: 192.186.10.0/24 vlan 33; 192.186.11.0/24 vlan 44
3、创建租户B网络环境(租户A已经在文章一创建完成)
1)创建network namespace
ip netns add ns03
ip netns add ns04
ip netns add router-ns2
2)创建veth口
ip link add veth11 type veth peer name veth12
ip link add veth13 type veth peer name veth14
ip link add veth15 type veth peer name veth16
ip link add veth17 type veth peer name veth18
3)连接网桥和namespace
ip link set veth11 netns ns03
ip link set veth13 netns router-ns2
ip link set veth15 netns router-ns2
ip link set veth17 netns ns04
ovs-vsctl add-port br-int veth12
ovs-vsctl add-port br-int veth14
ovs-vsctl add-port br-int veth16
ovs-vsctl add-port br-int veth18
4)打开网口和配置地址
ifconfig veth12 up
ifconfig veth14 up
ifconfig veth16 up
ifconfig veth18 up
ip netns exec ns03 ifconfig veth11 192.168.10.100/24 up
ip netns exec ns04 ifconfig veth17 192.168.10.110/24 up
ip netns exec router-ns2 ifconfig veth13 192.168.10.1/24 up
ip netns exec router-ns2 ifconfig veth15 192.168.11.1/24 up
5)打开namespace路由转发功能
ip netns exec router-ns2 sysctl -w net.ipv4.ip_forward=1
6)设置路由
ip netns exec ns04 route add -net 192.168.10.0/24 gw 192.168.11.1/24 dev veth17
ip netns exec ns03 route add -net 192.168.11.0/24 gw 192.168.10.1 dev veth11
4、实验结果图
1)ping 结果
2)ns03路由
3)ns04路由
4)router-ns2路由