• OVS+VXLAN实现两个宿主机上的VM间的通信


     

     一、组网图

     说明:

    1、使用网络命名空间表示vm1和vm2. 因为我没有两台物理服务器。

    2、使用virtualbox 的两条虚机模拟作为host1和host2。

    二、配置指导

    1、创建网桥 br0

     分别在host1和host2上输入命令

     #ovs-vsctl add-br br0

    2、创建网络命名空间,用来模拟VM

    分别在host1和host2上输入命令

    #ip netns add nsvm1

    #ip netns add nsvm2

     3、创建配对端口,一端加入到命名空间,同时配置ip地址

    在host1和host2上输入命令

    #ip link add tap1 type veth peer name tap2

    #ip link add tap3 type veth peer name tap4

    #ip link set tap1 netns nsvm1

    #ip link set tap3 netns nsvm2

    配置ip地址。

    #ip netns exec nsvm1 ip addr add 192.168.0.11/24 dev tap1  (host2上配置为 192.168.0.13)

    #ip netns exec nsvm2 ip addr add 192.168.0.12/24 dev tap3 (host2上配置为 192.168.0.14)

    设置端口up.

    #ip netns exec nsvm1 ip link set tap1 up

    #ip netns exec nsvm2 ip link set tap3 up

    #ip link set tap2 up

    #ip link set tap4 up

    4、端口加入网桥

    在host1和host2上输入命令

    #ovs-vsctl add-port br0 tap2

    #ovs-vsctl add-port br0 tap4

    5、验证本地网桥相连的VM间通信

    在host1上输入命令

    #ip netns exec nsvm1 ping 192.168.0.12

     6、配置vxlan隧道

    在host1上配置如下命令

    #ip link add vxlan0 type vxlan id 42 dstport 4789 remote 172.16.56.4 local 172.16.56.3 dev enp0s3

    #ip addr add 20.0.0.1/24 dev vxlan0

    #ip link set vxlan0 up

    在host2上进行对应配置(remote/local互换,以及ip)

    #ip link add vxlan0 type vxlan id 42 dstport 4789 remote 172.16.56.3 local 172.16.56.4 dev enp0s3

    #ip addr add 20.0.0.2/24 dev vxlan0

    #ip link set vxlan0 up

    删除主机上默认的INPUT iptables规则

    iptables -D INPUT 11

     7、验证跨主机的vxlan隧道端口间通信

    在host1上输入命令

    #ping 20.0.0.2

    8、vxlan0端口加入到网桥,实现跨主机的VM间通信

    在host1和host2上输入命令

    #ovs-vsctl add-port br0 vxlan0

    9、验证跨主机的VM通过vxlan隧道端口间通信

    抓包如下:

    三、结论:

     通过OVS+VXLAN隧道口,可以模拟出跨主机的VM间通过vxlan隧道的通信过程,从抓包结果看,也是有vxlan格式封装的。

  • 相关阅读:
    LeetCode_Spiral Matrix II
    省选模拟10 题解
    省选模拟9 题解
    省选模拟8 题解
    省选模拟7 题解
    省选模拟6 题解
    省选模拟5 题解
    省选模拟4 题解
    数学专题测试3 题解
    数学专题测试2 题解
  • 原文地址:https://www.cnblogs.com/zhouhaibing/p/11075046.html
Copyright © 2020-2023  润新知