配置端口镜像本地和远程分析
配置端口镜像
您可以使用端口镜像来复制数据包,并将副本发送到运行应用程序(如网络分析器或入侵检测应用程序)的设备,以便分析流量而不会延迟流量。您可以镜像进出端口或进入 VLAN 的流量,还可以将副本发送到本地接入接口或通过中继接口发送到 VLAN。
建议您在不使用端口镜像时将其禁用。避免产生性能问题 如果启用端口镜像,建议选择特定的输入接口,而不是使用 关键字。all
您还可以使用防火墙过滤器来限制镜像流量。
此任务使用增强型第 2 层软件 (ELS) 配置样式。如果交换机运行的软件不支持 ELS,请参阅 配置端口镜像。https://www.juniper.net/documentation/en_US/junos/topics/task/configuration/port-mirroring-qfx-series-cli.html有关 ELS 的详细信息,请参阅使用增强型第 2 层软件 CLI。
如果要在不删除现有分析器的情况下创建其他分析器,请先使用命令禁用 现有分析器。disable analyzer analyzer-name
必须将端口镜像输出接口 配置为 。family ethernet-switching
为本地分析配置端口镜像
要将接口流量镜像到交换机上的本地接口:
为远程分析配置端口镜像
要将流量镜像到 VLAN 以便在远程位置进行分析,请执行以下操作:
过滤进入分析器的流量
NFX150 设备不支持此功能。
除了通过配置分析器指定要镜像的流量外,您还可以使用防火墙过滤器来更好地控制要复制的数据包。例如,您可以使用筛选器指定仅镜像来自某些应用程序的流量。过滤器可以使用任何可用的匹配条件,并且必须具有修饰 符的操作 如果在多个过滤器或术语中使用相同的分析器,则输出数据包仅复制一次。port-mirror-instance instance-name.
当您使用防火墙过滤器作为端口镜像实例的输入时,您可以将复制的流量发送到本地接口或 VLAN,就像不涉及防火墙时一样。
要使用过滤器配置端口镜像:
在 SRX 系列防火墙上 配置端口镜像
要在 SRX 设备上配置端口镜像,必须先在层次结构级别配置 和。forwarding-options
interfaces
[edit]
您必须配置语句以 定义用于端口镜像的端口实例 ,并配置要镜像的接口。forwarding-options
mirror-to
镜像端口和镜像到端口必须位于 I/O 卡中的 同一 Broadcom 芯片组下。
要配置端口镜像:
您可以配置一个 子句来指定多个 端口。instance
mirror-to
要镜像接口,请在层次结构级别包含 语句 。 port-mirror-instance
[edit interface mirrored-intf-name]
镜像接口配置了实例名称,该名称在 中 定义。forwarding-options
端口和端口通过该实例链接。mirrored
mirror-to
instance { inst-name { input { rate number; run-length number; } family any { output { interface intf-name; } } } } interfaces mirrored-intf-name { port-mirror-instance instance-name; }
SRX 系列防火墙上的端口镜像不会区分流量方向,而是将入口和出口样本镜像在一起。
端口镜像的示例配置如下所示:
mirror port ge-1/0/2 to port ge-1/0/9.0 forwarding-options port-mirroring { input { rate 1; run-length 10; } family any { output { interface ge-1/0/9.0; } } instance { inst1 { input { rate 1; run-length 10; } family any { output { interface ge-1/0/9.0; } } } } interfaces { ge-1/0/2 { port-mirror-instance inst1; } }
示例:为本地分析配置端口镜像
使用端口镜像将流量发送到分析流量的应用程序,以便监控合规性、实施策略、检测入侵、监控和预测流量模式、关联事件等。端口镜像复制进出接口或进入 VLAN 的数据包,并将副本发送到本地接口进行本地监控。
此示例使用增强型第 2 层软件 (ELS) 配置样式。有关 ELS 的详细信息,请参阅 使用增强型第 2 层软件 CLI。
此示例介绍如何配置端口镜像,以将员工计算机发送到交换机的流量复制到同一交换机上的接入接口。
要求
此示例使用以下硬件和软件组件:
Junos OS 13.2 版
一个交换机
概述和拓扑
本主题包括两个相关示例,介绍如何将交换机上进入接口的流量镜像到同一交换机上的接入接口。第一个示例说明如何将员工计算机发送的所有流量镜像到交换机。第二个示例包括一个筛选器,用于仅镜像进入 Web 的员工流量。
拓扑
在此示例中, 并 用作员工计算机的连接。xe-0/0/0
xe-0/0/6
接口 连接到运行分析器应用程序的设备。xe-0/0/47
多个端口镜像到一个接口可能会导致缓冲区溢出和数据包丢失。
图 1 显示了此示例的网络拓扑。
示例:镜像所有员工流量以进行本地分析
要为员工计算机发送的所有流量配置端口镜像以进行本地分析,请执行本节中介绍的任务。
程序
CLI 快速配置
要为连接到员工计算机的两个端口的入口流量快速配置本地端口镜像,请复制以下命令并将其粘贴到交换机终端窗口中:
[edit] set interfaces xe-0/0/0 unit 0 family ethernet-switching set interfaces xe-0/0/6 unit 0 family ethernet-switching set interfaces xe-0/0/47 unit 0 family ethernet-switching set forwarding-options analyzer employee-monitor input ingress interface xe-0/0/0.0 set forwarding-options analyzer employee-monitor input ingress interface xe-0/0/6.0 set forwarding-options analyzer employee-monitor output interface xe-0/0/47.0
分步过程
要配置调用 的分析器并指定输入(源)接口和输出接口,请执行以下操作:employee-monitor
将连接到员工计算机的接口配置为端口镜像分析器的 输入接口:
employee-monitor
[edit forwarding-options] user@switch# set analyzer employee-monitor input ingress interface xe–0/0/0.0 user@switch# set analyzer employee-monitor input ingress interface xe–0/0/6.0
配置分析器的输出分析器接口 。
employee-monitor
这将是镜像数据包的目标接口:[edit forwarding-options] user@switch# set analyzer employee-monitor output interface xe-0/0/47.0
成果
检查配置结果:
[edit] user@switch# show forwarding-options analyzer employee-monitor { input { ingress { interface xe-0/0/0.0; interface xe-0/0/6.0; } } output { interface { xe-0/0/47.0; } } } }
示例:使用防火墙过滤器镜像员工 Web 流量
要求
此示例使用以下硬件和软件组件:
单QFX5100交换机
Junos OS 版本 14.1X53-D30
概述
通常希望仅镜像某些流量,而不是镜像所有流量。这样可以更有效地使用带宽和硬件,并且由于这些资产的限制,这可能是必要的。要选择要镜像的特定流量,请使用防火墙过滤器匹配所需流量并将其定向到端口镜像实例。然后,端口镜像实例复制数据包并将其发送到输出 VLAN、接口或 IP 地址。
配置
若要指定将镜像的唯一流量是员工发送到 Web 的流量,请执行本节中介绍的任务。要选择此流量进行镜像,请使用防火墙过滤器指定此流量并将其定向到端口镜像实例。
程序
CLI 快速配置
要快速配置来自员工计算机的发往 Web 的流量的本地端口镜像,请复制以下命令并将其粘贴到交换机终端窗口中:
[edit] set interface xe-0/0/47 unit 0 family ethernet-switching set forwarding-options port-mirroring instance employee–web–monitor family ethernet-switching output interface xe-0/0/47.0 set firewall family ethernet-switching filter watch-employee term employee-to-corp from ip-destination-address 192.0.2.16/28 set firewall family ethernet-switching filter watch-employee term employee-to-corp from ip-source-address 192.0.2.16/28 set firewall family ethernet-switching filter watch-employee term employee-to-corp then accept set firewall family ethernet-switching filter watch-employee term employee-to-web from destination-port 80 set firewall family ethernet-switching filter watch-employee term employee-to-web then port-mirror-instance employee-web-monitor set interfaces xe-0/0/0 unit 0 family ethernet-switching filter input watch-employee set interfaces xe-0/0/6 unit 0 family ethernet-switching filter input watch-employee
分步过程
要配置来自连接到员工计算机的两个端口的员工到 Web 流量的本地端口镜像,请执行以下操作:
配置输出接口:
[edit interfaces] user@switch# set xe-0/0/47 unit 0 family ethernet-switching
配置输出接口。
employee-web-monitor
(仅配置输出 — 输入来自过滤器。[edit forwarding-options] user@switch# set port-mirroring instance employee–web–monitor family ethernet-switching output interface xe-0/0/47.0
配置名为 的防火墙过滤器,该过滤器包含一个术语,用于匹配发送到 Web 的流量并将其发送到端口镜像实例 。
watch-employee
employee-web-monitor
不需要复制进出公司子网(目标 或源地址)的流量,因此请创建另一个术语,以便在流量到达将 Web 流量发送到实例的术语之前接受该流量:192.0.2.16/28
[edit firewall family ethernet-switching] user@switch# set filter watch-employee term employee-to-corp from ip-destination-address 192.0.2.16/28 user@switch# set filter watch-employee term employee-to-corp from ip-source-address 192.0.2.16/28 user@switch# set filter watch-employee term employee-to-corp then accept user@switch# set filter watch-employee term employee-to-web from destination-port 80 user@switch# set filter watch-employee term employee-to-web then port-mirror-instance employee-web-monitor
将防火墙过滤器作为入口过滤器应用于相应的接口(出口过滤器不允许分析器):
[edit interfaces] user@switch# set xe-0/0/0 unit 0 family ethernet-switching filter input watch-employee user@switch# set xe-0/0/6 unit 0 family ethernet-switching filter input watch-employee
成果
检查配置结果:
[edit] user@switch# show forwarding-options { port-mirroring { instance { employee-web-monitor { family ethernet-switching { output { interface xe-0/0/47.0; } } } } } } ... firewall { family ethernet-switching { filter watch-employee { term employee-to-corp { from { ip-source-address 192.0.2.16/28; ip-destination-address 192.0.2.16/28; } then accept; term employee-to-web { from { destination-port 80; } then port-mirror-instance employee-web-monitor; } } } } ... interfaces { xe-0/0/0 { unit 0 { family ethernet-switching { filter { input watch-employee; } } } } xe-0/0/6 { family ethernet-switching { filter { input watch-employee; } } } xe-0/0/47 { family ethernet-switching; } }
验证
验证是否已正确创建分析器
目的
验证是否已使用适当的输入接口和输出接口在交换机上创建名为的 端口镜像实例。employee-web-monitor
操作
您可以使用命令 验证端口镜像端口镜像实例是否已按预期配置。show forwarding-options port-mirroring
user@switch> show forwarding-options port-mirroring Instance name : employee-web-monitor Instance Id: 2 Input parameters: Rate :1 Run-length :0 Maximum packet length :0 Output parameters: Family State Destination Next-hop ethernet-switching up xe-0/0/47.0
意义
此输出显示有关端口镜像实例 的以下信息:employee-web-monitor
速率为 (镜像每个数据包,默认设置)
1
采样的连续数据包数(运行长度)为
0
镜像的原始数据包的最大大小为 ( 表示整个数据包)
0
0
输出参数的状态:
up
指示实例正在镜像进入 xe-0/0/0 和 xe-0/0/6 接口的流量,并将镜像的流量发送到 xe-0/0/47 接口
如果输出接口的状态为或未配置输出接口,则该值将为,并且不会对实例进行编程以进行镜像。down
state
down
示例:为远程分析配置端口镜像
使用端口镜像将流量发送到分析流量的应用程序,以便监控合规性、实施策略、检测入侵、监控和预测流量模式、关联事件等。端口镜像会复制进出接口或进入 VLAN 的数据包,并将副本发送到本地接口进行本地监控,或发送到 VLAN 进行远程监控。此示例介绍如何为远程分析配置端口镜像。
要求
此示例使用以下硬件和软件组件:
适用于 QFX 系列的 Junos OS 13.2 版
一个交换机
概述和拓扑
本主题包括两个相关示例,介绍如何将交换机上输入端口的流量镜像到分析器 VLAN,以便使用远程设备执行分析。第一个示例说明如何将员工计算机发送的所有流量镜像到交换机。第二个示例包括一个筛选器,用于仅镜像进入 Web 的员工流量。
拓扑
在此示例中:
接口 和 是连接到员工计算机的第 2 层接口。
ge-0/0/0
ge-0/0/1
接口是连接到另一台交换机的第 2 层接口 。
ge-0/0/2
VLAN 在拓扑中的所有交换机上均配置为承载镜像流量。
remote-analyzer
除了执行此处描述的配置步骤外,还必须在用于将源交换机(此配置中的交换机)连接到监控站所连接到的交换机的其他交换机上配置分析器 VLAN (在本例中)。remote-analyzer
镜像所有员工流量以进行远程分析
程序
CLI 快速配置
要快速配置示例的此部分,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,更改任何必要的详细信息以匹配您的网络配置,然后将命令复制并粘贴到层次结构级别的 CLI 中:edit
[edit] set vlans remote-analyzer vlan-id 999 set interfaces ge-0/0/10 unit 0 family ethernet-switching port-mode trunk set interfaces ge-0/0/10 unit 0 family ethernet-switching vlan members 999 set forwarding-options analyzer employee-monitor input ingress interface ge-0/0/0.0 set forwarding-options analyzer employee-monitor input ingress interface ge-0/0/1.0 set forwarding-options analyzer employee-monitor output vlan remote-analyzer
分步过程
要配置基本远程端口镜像:
配置分析器 VLAN(在本例中称为 ):
remote-analyzer
[edit vlans] user@switch# set vlans remote-analyzer vlan-id 999
将连接到另一台交换机的接口配置为中继模式,并将其与 VLAN 关联:
remote-analyzer
[edit interfaces] user@switch# set ge-0/0/10 unit 0 family ethernet-switching port-mode trunk user@switch# set ge-0/0/10 unit 0 family ethernet-switching vlan members 999
配置分析器 :
employee-monitor
[edit forwarding-options] user@switch# set analyzer employee–monitor user@switch# set analyzer employee-monitor input ingress interface ge-0/0/0.0 user@switch# set analyzer employee-monitor input ingress interface ge-0/0/1.0 user@switch# set analyzer employee-monitor output vlan remote-analyzer
在将此交换机连接到监控工作站的交换机上配置 VLAN。
remote-analyzer
成果
检查配置结果:
[edit] user@switch# show forwarding-options { analyzer employee-monitor { input { ingress { interface ge-0/0/0.0; interface ge-0/0/1.0; } } output { vlan { remote-analyzer; } } } }
镜像员工到 Web 的流量以进行远程分析
CLI 快速配置
要快速配置示例的此部分,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,更改任何必要的详细信息以匹配您的网络配置,然后将命令复制并粘贴到层次结构级别的 CLI 中:edit
[edit] set vlans remote-analyzer vlan-id 999 set interfaces ge-0/0/10 unit 0 family ethernet-switching interface-mode trunk set interfaces ge-0/0/10 unit 0 family ethernet-switching vlan members 999 set forwarding-options port-mirroring instance employee-web-monitor loss-priority high output vlan 999 set firewall family ethernet-switching filter watch-employee term employee-to-web from destination-port 80 set firewall family ethernet-switching filter watch-employee term employee-to-web then port-mirror-instance employee-web-monitor set ge-0/0/0 unit 0 family ethernet-switching filter input watch-employee set interfaces ge-0/0/1 unit 0 family ethernet-switching filter input watch-employee
程序
分步过程
配置分析器 VLAN(在本例中称为 ):
remote-analyzer
[edit vlans] user@switch# set remote-analyzer vlan-id 999
配置接口以将其与 VLAN 关联:
remote-analyzer
[edit interfaces] user@switch# set interfaces ge-0/0/10 unit 0 family ethernet-switching interface-mode trunk user@switch# set ge-0/0/10 unit 0 family ethernet-switching vlan members 999
配置分析器 。
employee-web-monitor
(仅配置输出 — 输入来自过滤器。[edit forwarding-options] user@switch# set forwarding-options port-mirroring instance employee-web-monitor output vlan 999
配置调用 的防火墙过滤器,以匹配发送到 Web 的流量并将其发送到分析器 :
watch-employee
employee-web-monitor
[edit firewall family ethernet-switching] user@switch# set filter watch-employee term employee-to-web from destination-port 80 user@switch# set filter watch-employee term employee-to-web then port-mirror-instance employee-web-monitor
将防火墙过滤器作为入口过滤器应用于相应的接口:
[edit interfaces] user@switch# set ge-0/0/0 unit 0 family ethernet-switching filterinput watch-employee user@switch# set ge-0/0/1 unit 0 family ethernet-switching filter input watch-employee
在将此交换机连接到监控工作站的交换机上配置 VLAN。
remote-analyzer
成果
检查配置结果:
[edit] user@switch# show interfaces { ... ge-0/0/10 { unit 0 { family ethernet-switching { interface-mode trunk; vlan { members remote-analyzer; } } } } ge-0/0/0 { unit 0 { family ethernet-switching { filter { input watch-employee; } } } } ge-0/0/1 { unit 0 { family ethernet-switching { filter { input watch-employee; } } } } } ... firewall { family ethernet-switching { ... filter watch-employee { term employee-to-web { from { destination-port 80; } then port-mirror-instance employee-web-monitor; } } } } forwarding-options analyzer { employee-web-monitor { output { vlan { 999; } } } vlans { remote-analyzer { vlan-id 999; } }
验证
验证是否已正确创建分析器
目的
验证是否已使用适当的输入接口和相应的输出接口在交换机上命名 或 创建的分析器。employee-monitor
employee-web-monitor
操作
可以使用命令 验证端口镜像分析器是否已按预期配置。show analyzer
user@switch> show analyzer Analyzer name : employee-monitor Output VLAN : remote-analyzer Ingress monitored interfaces : ge-0/0/0.0 Ingress monitored interfaces : ge-0/0/1.0
意义
此输出显示分析器正在镜像进入的流量,并将镜像流量发送到分析器。employee-monitor
ge-0/0/0
ge-0/0/1
remote-analyzer