Vas*_*lis 8 networking vlan virtualization namespace
我想使用网络命名空间(ns1 到 ns4)实现下图所示的拓扑。

我可以使用以下命令实现上述拓扑,而无需将网络拆分为两个不同的 VLAN(基于这篇文章,标题为:Linux 网络命名空间介绍):
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
Run Code Online (Sandbox Code Playgroud)
基于上述设置,每个人都可以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
Run Code Online (Sandbox Code Playgroud)
然而,每个人仍然可以 ping 其他人,这意味着网络没有分成两个不同的 LANS。我怎样才能实现我正在尝试的目标?虚拟接口的 VLAN 标记是否有不同的方法?
有几件事被混淆了:
vconfig调用将找不到 veth11 或 veth13,因为它们不在默认命名空间中。– 你没有得到任何错误!?ip过时ifconfig和vconfig