说明:服务器
一、使用网络命名空间表示vm1和vm2. 由于我没有两台物理服务器。网络
二、使用virtualbox 的两条虚机模拟做为host1和host2。spa
分别在host1和host2上输入命令blog
#ovs-vsctl add-br br0ip
分别在host1和host2上输入命令rem
#ip netns add nsvm1table
#ip netns add nsvm2virtualbox
在host1和host2上输入命令配置
#ip link add tap1 type veth peer name tap2iptables
#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
在host1和host2上输入命令
#ovs-vsctl add-port br0 tap2
#ovs-vsctl add-port br0 tap4
在host1上输入命令
#ip netns exec nsvm1 ping 192.168.0.12
在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
在host1上输入命令
#ping 20.0.0.2
八、vxlan0端口加入到网桥,实现跨主机的VM间通讯
在host1和host2上输入命令
#ovs-vsctl add-port br0 vxlan0
九、验证跨主机的VM经过vxlan隧道端口间通讯
抓包以下:
3、结论:
经过OVS+VXLAN隧道口,能够模拟出跨主机的VM间经过vxlan隧道的通讯过程,从抓包结果看,也是有vxlan格式封装的。