当前位置: 首页 > news >正文

bridge-vlan

# 1.topo


 # 2.创建命名空间
 ip netns add ns0
 ip netns add ns1
 ip netns add ns2
 ip netns add ns3

 # 3.创建veth设备
 ip link add ns0-veth0 type veth peer name hn0-veth0
 ip link add ns1-veth0 type veth peer name hn1-veth0
 ip link add ns2-veth0 type veth peer name hn2-veth0
 ip link add ns3-veth0 type veth peer name hn3-veth0

 # 4.veth设备放入命名空间,启动接口
 ip link set ns0-veth0 netns ns0
 ip link set ns1-veth0 netns ns1
 ip link set ns2-veth0 netns ns2
 ip link set ns3-veth0 netns ns3
 ip -netns ns0 link set ns0-veth0 up
 ip -netns ns1 link set ns1-veth0 up
 ip -netns ns2 link set ns2-veth0 up
 ip -netns ns3 link set ns3-veth0 up

 # 5.创建br0,启动br0过滤功能,添加接口到br0
 brctl addbr br0
 ip link set dev br0 type bridge vlan_filtering 1  //1是启用
 ip link set br0 up
 brctl addif br0 hn0-veth0
 brctl addif br0 hn1-veth0
 brctl addif br0 hn2-veth0
 brctl addif br0 hn3-veth0

 ip link set dev hn0-veth0 up
 ip link set dev hn1-veth0 up
 ip link set dev hn2-veth0 up
 ip link set dev hn3-veth0 up

 # 6.配置vlan
 bridge vlan add dev hn0-veth0 vid 10 pvid untagged
 bridge vlan add dev hn1-veth0 vid 20 pvid untagged
 bridge vlan add dev hn2-veth0 vid 10 pvid untagged
 bridge vlan add dev hn3-veth0 vid 20 pvid untagged


 # 7.配置地址
 ip -netns ns0 addr add 1.1.1.10/24 dev ns0-veth0
 ip -netns ns1 addr add 1.1.1.11/24 dev ns1-veth0
 ip -netns ns2 addr add 1.1.1.12/24 dev ns2-veth0
 ip -netns ns3 addr add 1.1.1.13/24 dev ns3-veth0


# 8.测试
# 8.1测试1
ip netns exec ns0 ping -c 3 -W 1 1.1.1.11  不通
ip netns exec ns0 ping -c 3 -W 1 1.1.1.12   通
tcpdump -i br0 -e

hn0-veth0 属于vlan 10  ,hn1-veth0 属于vlan 20  ,所以ip netns exec ns0 ping -c 3 -W 1 1.1.1.11  不通;

hn0-veth0 属于vlan 10  ,hn2-veth0 属于vlan 10 ,所以ip netns exec ns0 ping -c 3 -W 1 1.1.1.12   通


# 8.2测试2
ip netns exec ns1 ping -c 3 -W 1 1.1.1.12  不通
ip netns exec ns1 ping -c 3 -W 1 1.1.1.13  通
tcpdump -i br0 -e

同上;


# 9.删除

ip netns del ns0
ip netns del ns1
ip netns del ns2
ip netns del ns3

# 10.bridge vlan命令
bridge -c vlan show
bridge vlan del vid 100-200 dev eth0
bridge vlan add dev eth0 vid 10
bridge vlan add dev eth0 vid 10 pvid untagged
bridge vlan add dev br0 vid 20 self
ip -details add show br0

# 11.参考
VLAN - ArchWiki

networking - Linux VLAN-aware bridges and trunk ports - Unix & Linux Stack Exchange

http://www.lryc.cn/news/483663.html

相关文章:

  • 【赵渝强老师】MySQL InnoDB的数据文件与重做日志文件
  • 华为云前台展示公网访问需要购买EIP,EIP流量走向
  • 排序算法 -插入排序
  • 如何使用.bat实现电脑自动重启?
  • 使用VSCode远程连接服务器并解决Neo4j无法登陆问题
  • 使用React和Vite构建一个AirBnb Experiences克隆网站
  • HBase压测 ycsb
  • 基于Python+Django+Vue3+MySQL实现的前后端分类的商场车辆管理系统
  • 网络安全web基础_HTML基础(扫盲篇)
  • (附项目源码)Java开发语言,监督管家APP的设计与实现 58,计算机毕设程序开发+文案(LW+PPT)
  • 前端基础的讲解-JS(11)
  • Python魔法方法深度解析:解密__call__、__new__和__del__的核心奥义
  • 当微软windows的记事本被AI加持
  • Python酷库之旅-第三方库Pandas(213)
  • 普林斯顿:LLM基于边际优化的梯度纠缠
  • 通俗易懂:什么是 Java 类加载?
  • Dijkstra 算法的实现方案
  • OpenGL 进阶系列07 - 阴影贴图(shadowmap )
  • 【CAN介绍】【第一篇章】
  • 【统计子矩阵——部分前缀和+双指针】
  • 用正则表达式检查是IP否为内网地址
  • Leetcode刷题笔记14
  • PHP图书绘本借阅管理系统小程序源码
  • 【JavaWeb】JavaWeb入门之XML详解
  • JS手写-this绑定实现
  • 【时间之外】IT人求职和创业应知【31】
  • 如何使用ffmpeg命令行进行录屏
  • ODOO学习笔记(8):模块化架构的优势
  • 数字IC后端实现之Innovus specifyCellEdgeSpacing和ICC2 set_placement_spacing_rule的应用
  • 每日小练:Day2