第六课 k8s网络基础学习-掌握vlan

tags:

  • k8s网络
  • eNSP
  • wireshark
  • IPVLAN
  • MACVLAN

第一节 VLAN介绍

  1. VLAN (Virtual Local Area Network)即虚拟局域网,是将一个物理的LAN在逻辑上划分成多个广播域的通信技术。VLAN内的主机间可以直接通信,而VLAN间不能直接通信,从而将广播报文限制在一个VLAN内。
  2. 以太网是一种基于CSMACD (Carrier Sense Multiple Access/Collision Detection))的共享通讯介质的数据网络通讯技术。当主机数目较多时会导致冲突严重、广播泛滥、性能显著下降甚至造成网络不可用等问题。通过交换机实现LAN互连虽然可以解决冲突严重的问题,但仍然不能隔离广播报文和提升网络质量。
  3. 在这种情况下出现了VLAN技术,这种技术可以把一个LAN划分成多个逻辑的VLAN,每个VLAN是一个广播域,VLAN内的主机间通信就和在一个LAN内一样,而VLAN间则不能直接互通,这样,广播报文就被限制在一个VLAN内。
    在这里插入图片描述
  4. 划分vlan的好处:
    • 限制广播域: 广播域被限制在一个VLAN内,节省了带宽,提高了网络处理能力。
    • 增强局域网的安全性: 不同VLAN内的报文在传输时是相互隔离的,即一个VLAN内的用户不能和其它VLAN内的用户直接通信。
    • 提高了网络的健壮性:故障被限制在一个VLAN内,本VLAN内的故障不会影响其他VLAN的正常工作。
    • 灵活构建虚拟工作组:用VLAN可以划分不同的用户到不同的工作组,同一工作组的用户也不必局限于某一固定的物理范围,网络构建和维护更方便灵活。

第二节 VLAN Tag

  1. 要使设备能够分辨不同VLAN的报文,需要在报文中添加标识VLAN信息的字段。IEEE 802.1Q协议规定,在以太网数据帧的目的MAC地址和源MAC地址字段之后、协议类型字段之前加入4个字节的VLAN标签(又称VLAN Tag,简称Tag) ,用以标识VLAN信息
    在这里插入图片描述
  2. 因为TPID的标签可以自定义,所以不同厂家的设备的二层交换就可能会出问题。所以路由器使用同一家的。

第三节 VLAN PVID

  1. 缺省VLAN又称PVID(Port Default VLAN ID)这是华为和华三的叫法,思科叫做Native Vlan。设备处理的数据帧都带Tag,当设备收到Untagged帧时,就需要给该帧添加Tag,添加什么Tag,就由接口上的缺省VLAN决定。一个物理端口只能拥有一个PVID,当一个物理端口拥有了一个PVID的时候,必定会拥有和PVID相等的VlanID,而且在这个VID上,这个物理端口必定是Untagged Port。(就是在交换机内部所有数据帧都是带着vlan标签的)
  2. PVID的作用只是在交换机从外部接受到可以接受Untagged 数据帧的时候给数据帧添加TAG标记用的,在交换机内部转发数据的时候PVID不起任何作用。
    在这里插入图片描述
  3. 每个接口都有一个缺省VLAN。缺省情况下,所有接口的缺省VLAN均为VLAN1,但用户可以根据需要进行配置
    • 对于Access接口(思科默认是Access端口),缺省VLAN就是它允许通过的VLAN,修改缺省VLAN即可更改接口允许通过的VLAN。
    • 对于Trunk接口和Hybrid接口(华为华三默认是Hybrid接口),一个接口可以允许多个VLAN通过,但是只能有一个缺省VLAN。接口的缺省VLAN和允许通过的VLAN需要分别配置,互不影响。
      在这里插入图片描述
  4. 由上面各类接口添加或剥除VLAN标签的处理过程可见:
    • 当接收到不带VLAN标签的数据帧时,Access接口、Trunk接口、Hybrid接口都会给数据帧打上VLAN标签,但Trunk接口、Hybrid接口会根据数据帧的VID是否为其允许通过的VLAN来判断是否接收,而Access接口则无条件接收
    • 当接收到带VLAN标签的数据帧时,Access接口、Trunk接口、Hybrid接口都会根据数据帧的VID是否为其允许通过的VLAN (Access接口允许通过的VLAN就是缺省VLAN)来判断是否接收。
    • 当发送数据帧时:
      1. Access接口直接剥离数据帧中的VLAN标签。(对主机链接)
      2. Trunk接口只有在数据帧中的VID与接口的PVID相等时才会剥离数据帧中的VLAN标签。(交换机之间)
      3. Hybrid接口会根据接口上的配置判断是否剥离数据帧中的VLAN标签。(比较自由控制vlan标签)
  5. 因此,Access接口发出的数据帧肯定不带Tag,Trunk接口发出的数据帧只有一个VLAN的数据帧不带Tag,其他都带VLAN标签,Hybrid接口发出的数据帧可根据需要设置某些VLAN的数据帧带Tag,某些VLAN的数据帧不带Tag。

第四节 VLAN Access Port

  1. Access接口:[PVID=VLAN ID] 在华为的交换机上配置时需要将Hybrid接口指定为Access Port
  2. Access接口一般用于和不能识别Tag的用户终端(如用户主机、服务器等)相连,或者不需要区分不同VLAN成员:使用。它只能收发Untagged帧,且只能为Untagged帧添加唯一VLAN的Tag。
  3. 处理过程如下。
    在这里插入图片描述
  4. eNSP的上图的拓扑图如下。
    在这里插入图片描述
# 查看路由器LSW3上的配置
dis current-configuration
# 查看 g 0/0/1 的配置 是access端口 因为我们改了它
int g0/0/1
dis thi

 port link-type access # 把端口变成access端口
 port default vlan 10 # vlanid 设置成10
# 使用下面命令可以看到 默认是hybrid的端口
dis port vlan
# 在pc4的出接口和pc5的入接口 抓包可以看到没有pvid的
# 查看路由器LSW9上的配置 主要看g 0/0/1 和 g 0/0/2的端口
dis current-configuration
dis port vlan # 看到g 0/0/1 是hybrid的端口
int g0/0/1
dis thi
# 看到下面
port hybrid pvid vlan 10 # 把pvid设置为vlan 10
port hybrid tagged vlan 10 # tag也是 vlan 10

第五节 VLAN Trunk Port

  1. Trunk接口:Trunk接口一般用于连接交换机、路由器、AP以及可同时收发Tagged帧和Untagged帧的语音终端。它可以允许多个VLAN的帧带Tag通过,但只允许一个VLAN的帧从该类接口上发出时不带Tag(即剥除Tag).
    在这里插入图片描述
  2. eNSP的上图的拓扑图如下。LSW2 的Trunk允许通过vlan 10和20的数据包
    在这里插入图片描述

第六节 VLAN Hybrid Port

  1. Hybrid接口(华为华三交换机上默认的接口):Hybrid接口既可以用于连接不能识别Tag的用户终端(如用户主机、服务器)和网络设备(如Hub),也可用于连接交换机、路由器以及可同时收发Tagged帧和Untagged帧的语音终端、AP。它可允许多个VLAN的帧带Tag通过,且允许从该类接口发出的帧根据需要配置某些VLAN的帧带Tag(即不剥除Tag)某些VLAN的帧不带Tag (即剥除Tag)。
    在这里插入图片描述

  2. eNSP的上图的拓扑图如下。
    在这里插入图片描述

第七节 linux bridge 实现vlan

在这里插入图片描述

  1. centos下实现上图。vlan10 指的是它的地址 3001值得是vlan标签。
# 加载vlan模块和必要的工具
# apt-get install vlan
yum install epel-release -y
yum install vconfig -y
# 内核载入模组
modprobe -a 8021q
# 确认内核是够载入了802.1q模组 成功才可以用vlan
lsmod | grep 8021q 

[root@localhost ~]# lsmod | grep 8021q
8021q                  32768  0
garp                   16384  1 8021q
mrp                    20480  1 8021q

# 创建网桥
brctl addbr br-test-vlan
# 创建veth对
ip link add veth01 type veth peer name veth10
ip link add veth02 type veth peer name veth20
# 将veth对的一段添加到网桥
brctl addif br-test-vlan veth01
brctl addif br-test-vlan veth02

# 创建网络名字空间
ip netns add test-vlan-vm01
ip netns add test-vlan-vm02
# 将设备对儿的另一端添加到两个名字空间
ip link set veth10 netns test-vlan-vm01
ip link set veth20 netns test-vlan-vm02

# 启动设备
ip link set dev br-test-vlan up
ip link set dev veth01 up
ip link set dev veth02 up
ip netns exec test-vlan-vm01 ip link set dev veth10 up
ip netns exec test-vlan-vm02 ip link set dev veth20 up

# 创建vlan 配置vlan 3001和vlan 3002
ip netns exec test-vlan-vm01 bash # 进入ns test-vlan-vm01 
vconfig add veth10 3001
vconfig add veth10 3002
ifconfig
# 启动两个vlan的设备
ifconfig veth10 up
ip link set veth10.3001 up
ip link set veth10.3002 up
ifconfig
# 分别在两个vlan上配置ip
ip a add 172.16.30.1/24 dev veth10.3001
ip a add 172.16.30.2/24 dev veth10.3002
exit # 退出ns test-vlan-vm01 


# 配置名称空间test-vlan-vm02
ip netns exec test-vlan-vm02 bash
# 配置vlan 3001和vlan 3002
vconfig add veth20 3001
vconfig add veth20 3002 
# 启动两个vlan的设备
ifconfig veth20 up
ip link set veth20.3001 up
ip link set veth20.3002 up 
# 分别在两个vlan上配置ip
ip a add 172.16.30.21/24 dev veth20.3001
ip a add 172.16.30.22/24 dev veth20.3002
# 在test-vlan-vm02中ping test-vlan-vm01 的 可以ping同
ping 172.16.30.1
ping 172.16.30.2
exit # 退出test-vlan-vm02

第八节 OVS bridge 实现vlan

  1. 上面实验是二层交换机的vlan,这里是OVS交换的三层Vlan。通过truck两个虚拟路由器连接在一起。
    在这里插入图片描述
  2. 安装openvswitch环境。
# 1.安装必须依赖包
yum -y install make gcc openssl-devel autoconf automake rpm-build redhat-rpm-config
yum -y install python-devel openssl-devel kernel-devel kernel-debug-devel libtool wget
# ⒉.准备环境
mkdir -p ~/rpmbuild/SOURCES
wget http://openvswitch.org/releases/openvswitch-2.5.0.tar.gz
cp openvswitch-2.5.0.tar.gz ~/rpmbuild/SOURCES/
tar xfz openvswitch-2.5.0.tar.gz
sed 's/openvswitch-kmod,//g' openvswitch-2.5.0/rhel/openvswitch.spec > openvswitch-2.5.0/rhel/openswich_no_kmod.spec
# 3.构建RPM包
cd ~/rpmbuild/SOURCES/openvswitch-2.5.0/rhel
rpmbuild -bb --nocheck openswich_no_kmod.spec 
# 4. 安装
yum localinstall ~/rpmbuild/RPMS/x86_64/openvswitch-2.5.0-1.x86_64.rpm
# 5.启动服务
systemctl enable openvswitch.service
systemctl start openvswitch.service
systemctl status openvswitch.service
# 6.查看ovs版本
ovs-appctl --version
# 7.查看流表
# ovs-ofctl dump-flows vswitch0
  1. 上面实验实现如下。https://zhuanlan.zhihu.com/p/37408055
# 1.使用docker创建四个不带网卡的容器
docker run -t -i -d --name vm01 --net=none --privileged centos:7 /bin/bash
docker run -t -i -d --name vm02 --net=none --privileged centos:7 /bin/bash
docker run -t -i -d --name vm03 --net=none --privileged centos:7 /bin/bash
docker run -t -i -d --name vm04 --net=none --privileged centos:7 /bin/bash
# ⒉.创建OVS网桥
ovs-vsctl add-br vswitch0
ovs-vsctl add-br vswitch1
# 3.使用ovs-docker工具给容器添加网卡到ovs网桥
ovs-docker add-port vswitch0 eth0 vm01 --ipaddress=192.168.1.2/24
ovs-docker add-port vswitch1 eth0 vm02 --ipaddress=192.168.1.3/24
ovs-docker add-port vswitch0 eth0 vm03 --ipaddress=192.168.1.4/24
ovs-docker add-port vswitch1 eth0 vm04 --ipaddress=192.168.1.5/24
# 4.连接vswitch0和vswitch1
ovs-vsctl add-port vswitch0 patch_to_vswitch1
ovs-vsctl add-port vswitch1 patch_to_vswitch0
ovs-vsctl set interface patch_to_vswitch1 type=patch
ovs-vsctl set interface patch_to_vswitch0 type=patch
ovs-vsctl set interface patch_to_vswitch0 options:peer=patch_to_vswitch1
ovs-vsctl set interface patch_to_vswitch1 options:peer=patch_to_vswitch0
# 5.查看ovs网桥的所有端口
ovs-vsctl show
# 5.配置VLAN Tag 
# 先通过ovs-vsctl show 获得interface 然后通过下面命令获得interface连接的容器
# 为vm01、vm02对应的ovs端口设置tag为100,为vm03、vm04对应的ovs端口设置tag为200
ovs-vsctl list interface 5d75e7dc74844_l | grep container_id
ovs-vsctl set port 5d75e7dc74844_l tag=200 # vm04 200
ovs-vsctl list interface 492586e2eae74_l | grep container_id
ovs-vsctl set port 492586e2eae74_l tag=100 # vm02 100
ovs-vsctl list interface b57344f0af114_l | grep container_id
ovs-vsctl set port b57344f0af114_l tag=200 # vm03
ovs-vsctl list interface 62abafae91684_l | grep container_id
ovs-vsctl set port 62abafae91684_l tag=100 # vm01

# 6.设置网桥之间的patch端口trunk100,200
ovs-vsctl set port patch_to_vswitch1 VLAN_mode=trunk
ovs-vsctl set port patch_to_vswitch0 VLAN_mode=trunk
ovs-vsctl set port patch_to_vswitch0 trunk=100
ovs-vsctl set port patch_to_vswitch1 trunk=100
# 7. ping测试结果 vm01只能ping通设置了相同tag的vm02,其他容器则无法ping通
docker exec -it vm01 bash
# vm01和vm02互通
ping 192.168.1.3

# 8. 配置trunk 200 vm03和vm04互通
ovs-vsctl set port patch_to_vswitch0 trunk=200
ovs-vsctl set port patch_to_vswitch1 trunk=200
docker exec -it vm03 bash
# vm01和vm02互通
ping 192.168.1.5

# 9. 抓包验证下 -e 在输出行打印出数据链路层的头部信息。 -f 将外部的Internet地址以数字的形式打印出来。-i 指定监听的网络接口。https://www.cnblogs.com/zhuimengle/p/5737848.html
tcpdump -e -i any -f icmp

./mongoexport --host=10.0.11.57 --port=27018 -u root -p 8cDs0tUFA@Vh2M9 --authenticationDatabase=admin -d used_car -c cars_info_4 --type=csv --fields= -o ~/cars_info_4.csv


第九节 ovs-toolbox工具实现vlan

  1. 介绍一个ovs的工具,python写的:https://github.com/nbonnand/ovs-toolbox/tree/v1.0.8
  2. 准备一个带界面的centos7。安装docker、openvswitch、python3
# 第一:安装docker
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install -y docker-ce-19.03.8 docker-ce-cli-19.03.8 containerd.io
cat <<EOF > /etc/docker/daemon.json
{
    "exec-opts": ["native.cgroupdriver=systemd"],
    "registry-mirrors": [
   		"https://registry.cn-hangzhou.aliyuncs.com",
   		 "https://fz5yth0r.mirror.aliyuncs.com",
          "https://dockerhub.mirrors.nwafu.edu.cn/",
          "https://mirror.ccs.tencentyun.com",
          "https://docker.mirrors.ustc.edu.cn/",
          "https://reg-mirror.qiniu.com",
          "http://hub-mirror.c.163.com/",
          "https://registry.docker-cn.com"
    ]
}
EOF
systemctl enable docker && systemctl start docker


# 第二:内核4.4以上才能稳定支持IPVLAN。
yum install -y brctl net-tools
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
yum --enablerepo=elrepo-kernel install kernel-ml-devel kernel-ml -y
grub2-set-default 0
reboot
uname -r

# 第三:安装openvswitch环境
yum -y install make gcc openssl-devel autoconf automake rpm-build redhat-rpm-config
yum -y install python-devel openssl-devel kernel-devel kernel-debug-devel libtool wget
mkdir -p ~/rpmbuild/SOURCES
wget http://openvswitch.org/releases/openvswitch-2.5.0.tar.gz
cp openvswitch-2.5.0.tar.gz ~/rpmbuild/SOURCES/
tar xfz openvswitch-2.5.0.tar.gz
sed 's/openvswitch-kmod,//g' openvswitch-2.5.0/rhel/openvswitch.spec > openvswitch-2.5.0/rhel/openswich_no_kmod.spec
cd ~/rpmbuild/SOURCES/openvswitch-2.5.0/rhel
rpmbuild -bb --nocheck openswich_no_kmod.spec 
yum localinstall ~/rpmbuild/RPMS/x86_64/openvswitch-2.5.0-1.x86_64.rpm
systemctl enable openvswitch.service
systemctl start openvswitch.service
systemctl status openvswitch.service
ovs-appctl --version

# 第四:安装liunx bridge
yum -y install bridge-utils
brctl show

# 第五:IPIP打开IP FORWARD 开启内核转发
echo 1 >/proc/sys/net/ipv4/ip_forward
cat /proc/sys/net/ipv4/ip_forward
# 加载ipip模块
modprobe ipip
lsmod | grep ipip

# 安装python3
yum install libffi-devel -y
wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz
tar -zxvf Python-3.7.0.tgz
cd Python-3.7.0
mkdir -p /usr/local/python37
./configure --prefix=/usr/local/python37
make && make install
ln -s /usr/local/python37/bin/python3.7 /usr/bin/python3
ln -s /usr/local/python37/bin/pip3.7 /usr/bin/pip3

# 安装ovs-toolbox https://github.com/nbonnand/ovs-toolbox/tree/v1.0.9
# https://developer.aliyun.com/mirror/ 下载 plotnetcfg-0.4.1-2.el7.x86_64.rpm
rpm -ihv plotnetcfg-0.4.1-2.el7.x86_64.rpm
yum -y install graphviz
# pip3 install pydot
- pyQt5
- lxml
- paramiko

# 启动ovs-toolbox
python3 ovs-toolbox.py
  1. 导入镜像 burly.tar。burlyluo/nettoolbox 。先创建两个ovs的bridge。
docker tag burlyluo/nettoolbox:v3 qnhyn/myapp:v1
# 查看是否创建成功
ovs-vsctl show

在这里插入图片描述
4. 刷新docker镜像,创建运行模板并上传。$$表示占位符。

# 运行时模板
# DOCK$$
# --privileged --net none -it -d
# /bin/bash
# 这里我们模板中没有对容器创建网络
docker exec -it DOCK01 bash
ifconfig # 只能看到回环口

在这里插入图片描述在这里插入图片描述
5. 容器创建一个对外的网卡如下。

# 网卡模板
# DOCK$$
# aa:00:00:00:00:$$
# /bin/bash
# 这里我们模板中没有对容器创建网络
docker exec -it DOCK01 bash
ifconfig # 可以看到网卡和网桥的变化
ovs-vsctl show

在这里插入图片描述
在这里插入图片描述
6. 选中br1将上面重复一次,容器从04到06。创建br1上的三个容器。
7. 设置br0上端口的Vlan标签。

# P01 tag 100 mode access
# P02 tag 150 mode access
# P03 是做流量镜像的 不能打标签
# PA 输入回车 创建trunk 100, 150 mode trunk
# PA IF Type 类型patch peer PB

# 同理br1上也创建端口的Vlan
# P04 tag 100 mode access
# P05 tag 150 mode access
# P06 是做流量镜像的 不能打标签
# PB 输入回车 创建trunk 100, 150 mode trunk
# PB IF Type 类型patch peer PA

在这里插入图片描述在这里插入图片描述在这里插入图片描述
8. ping测试

# dock01 和 docker04,  dock02 和 docker05 可以ping通过
 docker exec -it DOCK01 bash
# 但是如果直接使用tcpdump抓包 抓不到的都是些0x0800的包 如下
[root@localhost ~]# tcpdump -n -e -i any icmp
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on any, link-type LINUX_SLL (Linux cooked), capture size 262144 bytes
23:25:22.449781   P aa:00:00:00:00:01 ethertype IPv4 (0x0800), length 100: 10.0.0.1 > 10.0.0.4: ICMP echo request, id 7424, seq 0, length 64
23:25:22.449970 Out aa:00:00:00:00:01 ethertype IPv4 (0x0800), length 100: 10.0.0.1 > 10.0.0.4: ICMP echo request, id 7424, seq 0, length 64
  1. 给DOCK03和DOCK06做端口镜像,就可以抓到包。P3和P6上不能打tag,要不又抓不到包了。
# 下图表示把所有交换机的流量镜像到DOCK06上但是只要tag是100的
# 到DOCK06上抓包
docker exec -it DOCK06 bash 
tcpdump -n -e -i any icmp or arp

# 到DOCK01上发起请求
docker exec -it DOCK01 bash
ping 10.0.0.4

# 抓到包格式如下
15:35:22.316013   P aa:00:00:00:00:01 ethertype 802.1Q (0x8100), length 104: vlan 100, p 0, ethertype IPv4, 10.0.0.1 > 10.0.0.4: ICMP echo request, id 8960, seq 0, length 64
15:35:22.316181   P aa:00:00:00:00:04 ethertype 802.1Q (0x8100), length 104: vlan 100, p 0, ethertype IPv4, 10.0.0.4 > 10.0.0.1: ICMP echo reply, id 8960, seq 0, length 64
15:35:23.315956   P aa:00:00:00:00:01 ethertype 802.1Q (0x8100), length 104: vlan 100, p 0, ethertype IPv4, 10.0.0.1 > 10.0.0.4: ICMP echo request, id 8960, seq 1, length 64
15:35:23.316034   P aa:00:00:00:00:04 ethertype 802.1Q (0x8100), length 104: vlan 100, p 0, ethertype IPv4, 10.0.0.4 > 10.0.0.1: ICMP echo reply, id 8960, seq 1, length 64

在这里插入图片描述

  1. 这个工具内部用到的命令都写在日志里,可以导出自己使用。
  2. 通过ns实验 网桥上p1 访问 p2的流量 镜像到p3上
# 通过ns实验 网桥上p1 访问 p2的流量 镜像到p3上
ovs-vsctl add-br mtest

ip netns add test1
ip netns add test2
ip netns add test3

ovs-vsctl add-port mtest p1 -- set interface p1 type=internal
ovs-vsctl add-port mtest p2 -- set interface p2 type=internal
ovs-vsctl add-port mtest p3 -- set interface p3 type=internal

ip l s dev p1 netns test1
ip l s dev p2 netns test2
ip l s dev p3 netns test3

ip netns exec test1 ip a a 192.168.1.11/24 dev p1
ip netns exec test2 ip a a 192.168.1.12/24 dev p2

ovs-vsctl set port p1 tag=10
ovs-vsctl set port p2 tag=10

ip netns exec test1 ip l s p1 up
ip netns exec test2 ip l s p2 up
ip netns exec test3 ip link set up p3

ip netns exec test1 ping 192.168.1.12

# 现在抓包肯定 看不到vlan标签的 添加端口镜像
ovs-vsctl -- --id=@p2 get port p2 -- --id=@p3 get port p3 -- --id=@m create mirror name=m0 select-dst-port=@p2 output-port=@p3 -- set bridge mtest mirrors=@m
ovs-vsctl clear bridge mtest mirror
ovs-vsctl -- --id=@p2 get port p2 -- --id=@p3 get port p3 -- --id=@m create mirror name=m0 select-all=true output-port=@p3 -- set bridge mtest mirrors=@m
# 抓包 可以看到抓到数据包
ip netns exec test3 bash
tcpdump -n -e -i any icmp or arp

ip netns exec test1 ping 192.168.1.12

# ovs-vsctl -- --id=@patch_to_vswitch1 get port patch_to_vswitch1 -- --id=@d324d50982cc4_l get port d324d50982cc4_l -- --id=@m create mirror name=m0 select-all=@patch_to_vswitch1 output-port=@d324d50982cc4_l -- set bridge vswitch0 mirrors=@m
#创建mirror
#指定mirror名称,name={name}
#指定流量:
#select-all: true,表示此bridge上的所有流量;
#select-dst-port: 镜像从此port离开的流量;
#select-src-port: 镜像从此port进入的流量;
#select-vlan: 镜像此VLAN下的数据流量。
#指定镜像目的端口:
#output-port: 流量镜像至此端口;
#output-vlan: 流量镜像至指定vlan,镜像至指定VLAN时,原始tag会被剥离。
#

#清除mirror:
ovs-vsctl clear bridge mtest mirror

# 抓到的包如下
[root@localhost ~]# ip netns exec test3 ip link set up p3
[root@localhost ~]# ip netns exec test3 bash
[root@localhost ~]# tcpdump -n -e -i any icmp or arp
\tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on any, link-type LINUX_SLL (Linux cooked), capture size 262144 bytes
00:35:40.878317   P 2a:33:e3:65:e4:7c ethertype 802.1Q (0x8100), length 104: vlan 10, p 0, ethertype IPv4, 192.168.1.12 > 192.168.1.11: ICMP echo request, id 28274, seq 1, length 64
00:35:40.878437   P 72:30:6b:78:9e:db ethertype 802.1Q (0x8100), length 104: vlan 10, p 0, ethertype IPv4, 192.168.1.11 > 192.168.1.12: ICMP echo reply, id 28274, seq 1, length 64
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐