
# 查看内核
uname -r
ip netns list
# 如果有虚拟网卡对就删除
# ip netns delete xxx
clear
# 加载vlan模块和必要的工具
apt-get install vlan
modprobe 8021q
sh -c 'grep -q 8021q /etc/modules || echo 8021q >> /etc/modules'
# 创建网桥
# 如果存在可以先删除
#ifconfig br-test-vlan down
#brctl delbr br-test-vlan
brctl addbr br-test-vlan
brctl list
brctl show
# 创建veth对
ip link add veth01 type veth peer name veth10
ip link add veth03 type veth peer name veth30
# 将veth对的一段添加到网桥
brctl addif br-test-vlan veth01
brctl addif br-test-vlan veth03
# 启动设备
ip link set dev br-test-vlan up
ip link set dev veth01 up
ip link set dev veth03 up
ip link set dev veth10 up
ip link set dev veth30 up
# 创建网络名字空间
ip netns add ns1
ip netns add ns3
# 将设备对儿的另一端添加到两个名字空间
ip link set veth10 netns ns1
ip link set veth30 netns ns3
# 配置vlan 3001和vlan 3003
ip netns exec ns1 bash
vconfig add veth10 3001
vconfig add veth10 3003
# 启动两个vlan的设备
ifconfig veth10 up
ip link set veth10.3001 up
ip link set veth10.3003 up
# 分别在两个vlan上配置ip
ip a add 172.16.30.1/24 dev veth10.3001
ip a add 172.16.30.3/24 dev veth10.3003
# 配置名称空间ns3
ip netns exec ns3 bash
# 配置vlan 3001 和 vlan 3003
vconfig add veth30 3001
vconfig add veth30 3003
# 启动两个vlan的设备
ifconfig veth30 up
ip link set veth30.3001 up
ip link set veth30.3003 up
# 分别在两个vlan上配置ip
ip a add 172.16.30.21/24 dev veth30.3001
ip a add 172.16.30.22/24 dev veth30.3003
测试
通过抓包测试
tcpdump -i any -w vlan.cap
欢迎加群讨论技术,1群:677373950(满了,可以加,但通过不了),2群:656732739
评价
排名
2
文章
657
粉丝
44
评论
93
docker中Sware集群与service
尘叶心繁 : 想学呀!我教你呀
一个bug让程序员走上法庭 索赔金额达400亿日元
叼着奶瓶逛酒吧 : 所以说做程序员也要懂点法律知识
.net core 塑形资源
剑轩 : 收藏收藏
映射AutoMapper
剑轩 :
好是好,这个对效率影响大不大哇,效率高不高
一个bug让程序员走上法庭 索赔金额达400亿日元
剑轩 : 有点可怕
ASP.NET Core 服务注册生命周期
剑轩 :
http://www.tnblog.net/aojiancc2/article/details/167
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2025TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:
50010702506256


欢迎加群交流技术