linux下vxlan网络配置

2021/8/16 7:06:18

本文主要是介绍linux下vxlan网络配置,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

目标:在一台linux机器上,配置3个netns, 模拟3个节点,实现3个节点通过vxlan互通。 

连接图如下图所示:

(1)包括3个netns: net0,net1,net2

(2)每个netns下有一个vxlan(vxlan0,vxlan1,vxlan2)接口,其master为bridge(br0,br1,br2)。

(3)vxlan0,vxlan1,vxlan2通过虚拟网络设备veth(veth0b,veth1b,veth2b)进行交互。
(4)veth0b,veth1b,veth2b与veth0a,veth1a,veth2a是veth pair,  通过将veth0a,veth1a,veth2a连接到同一网桥br3,实现互通。

 

 

 

配置方法:

因为三个netns配置相似,以net0说明。

1、ip link add br3 type bridge; ip link set br3 up(添加br3网桥)

2、ip link add veth0a type veth peer name veth0b; ip link set veth0a up; ip link set veth0b up;ip link set veth0a master br3(添加veth pair,设置一端的master为br3)

3、ip netns add net0

4、ip link set veth0b netns net0(将veth的另一端放了netns)

进入net0进行配置

5、ip netns exec net0 bash(进入net0空间)

6、ip link set lo up;ip link set veth0b up; ip addr add 192.168.1.1/24 dev veth0b (设置lo为up, 这样可以ping通自己)

7、ip link add br0 type bridge; ip link set br0 up; ip addr add 172.28.1.1/24 dev br0(添加br0网桥)

8、ip link add vxlan0 type vxlan id 42 dstport 4789; ip link set vxlan0 up; ip link set vxlan0 master br0 (添加vxlan0,设置master为br0)

9、bridge fdb append 00:00:00:00:00:00 dev vxlan0 dst 192.168.1.2 via veth0b

      bridge fdb append 00:00:00:00:00:00 dev vxlan0 dst 192.168.1.3 via veth0b (配置vxlan0转发表项)

 

同样配置了net1,net2两个空间下的vxlan,三个bridge(br0,br1,br2)就可以互相ping通了。

 

参考:

1、https://www.jianshu.com/p/486d55b62f9c

2、https://fuckcloudnative.io/posts/vxlan-protocol-introduction/#vxlan-%E7%9A%84-flood-%E4%B8%8E-learn

3、https://zhuanlan.zhihu.com/p/133952983

4、https://blog.csdn.net/leafrenchleaf/article/details/84763817



这篇关于linux下vxlan网络配置的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程