在networking命名空间之间创buildVLAN

我想使用networking命名空间(ns1到ns4)来实现下图所示的拓扑。

拓扑来实现

我可以使用以下命令(基于本文标题为“Linuxnetworking命名空间简介” )实现上述拓扑,而不将networking分为两个不同的VLAN:

sudo ip netns add ns1 sudo ip netns add ns2 sudo ip netns add ns3 sudo ip netns add ns4 sudo ip link add veth1 type veth peer name veth11 sudo ip link add veth2 type veth peer name veth12 sudo ip link add veth3 type veth peer name veth13 sudo ip link add veth4 type veth peer name veth14 sudo ip link set veth11 netns ns1 sudo ip link set veth12 netns ns2 sudo ip link set veth13 netns ns3 sudo ip link set veth14 netns ns4 sudo ip netns exec ns1 ifconfig lo up sudo ip netns exec ns2 ifconfig lo up sudo ip netns exec ns3 ifconfig lo up sudo ip netns exec ns4 ifconfig lo up sudo ifconfig veth1 10.1.11.1/24 up sudo ifconfig veth2 10.1.12.1/24 up sudo ifconfig veth3 10.1.13.1/24 up sudo ifconfig veth4 10.1.14.1/24 up sudo ip netns exec ns1 ifconfig veth11 10.1.11.2/24 up sudo ip netns exec ns2 ifconfig veth12 10.1.12.2/24 up sudo ip netns exec ns3 ifconfig veth13 10.1.13.2/24 up sudo ip netns exec ns4 ifconfig veth14 10.1.14.2/24 up sudo ip netns exec ns1 route add default gw 10.1.11.1 veth11 sudo ip netns exec ns2 route add default gw 10.1.12.1 veth12 sudo ip netns exec ns3 route add default gw 10.1.13.1 veth13 sudo ip netns exec ns4 route add default gw 10.1.14.1 veth14 

基于上面的设置,每个人都可以ping其他人。 现在我想在一个VLAN中隔离ns1和ns3,在另一个VLAN中隔离ns2和ns4。 要实现VLAN的我试图使用类似于以下内容:

 sudo vconfig add veth1 11 sudo vconfig add veth3 11 sudo vconfig add veth11 12 sudo vconfig add veth13 12 

但是,仍然每个人都可以ping其他人意味着networking不分成两个不同的LANS。 我怎样才能达到我想要的? 虚拟接口的VLAN标记有不同的方法吗?

veth [1,2,3,4]仍然在全局名字空间中,因此被内核路由。

您的vconfig命令正在将vlan接口添加到相应的veth中,这不是您想要的。 ( ip link show应显示一个veth1.11等(取决于如何设置name_type))

我不确定你想用VLAN来完成什么。 如果要隔离n1 + n3和ns2 + ns4,则将veth的另一端移到不同的名称空间:

 ip netns add blue ip link set netns veth1 blue ip link set netns veth3 blue ip netns add yellow ip link set netns veth2 yellow ip link set netns veth4 yellow