配置端口镜像本地和远程分析
配置端口镜像
您可以使用端口镜像来复制数据包,并将这些副本发送到运行应用(如网络分析器或入侵检测应用)的设备,这样您就可以在不延迟流量的情况下分析流量。您可以镜像进出端口或进入 VLAN 的流量,并且可以通过中继接口将副本发送到本地接入接口或 VLAN。
建议您在不使用端口镜像时禁用端口镜像。为避免造成性能问题,如果启用了端口镜像,建议选择特定的输入接口,而不是使用 all 关键字。您还可以使用防火墙过滤器来限制镜像流量。
此任务使用增强型第 2 层软件 (ELS) 配置样式。如果交换机运行的软件不支持 ELS,请参阅 配置端口镜像。有关 ELS 的详细信息,请参阅 使用增强型第 2 层软件 CLI。
如果要在不删除现有分析器的情况下创建其他分析器,请先使用 disable analyzer analyzer-name 命令禁用现有分析器。
您必须将端口镜像输出接口配置为 family ethernet-switching。
配置端口镜像以进行本地分析
要将接口流量镜像到交换机上的本地接口,请执行以下操作:
配置端口镜像以进行远程分析
要将流量镜像到 VLAN 以便在远程位置进行分析:
过滤进入分析器的流量
NFX150 设备不支持此功能。
除了通过配置分析器指定要镜像哪些流量外,您还可以使用防火墙过滤器更好地控制复制的数据包。例如,您可以使用过滤器指定仅镜像来自某些应用的流量。过滤器可以使用任何可用的匹配条件,并且必须具有 如果 port-mirror-instance instance-name. 在多个过滤器或术语中使用同一分析器,则输出数据包只会复制一次。
使用防火墙过滤器作为端口镜像实例的输入时,可以将复制的流量发送到本地接口或 VLAN,就像在不涉及防火墙时一样。
要使用过滤器配置端口镜像:
在 SRX 系列防火墙上配置端口镜像
要在 SRX 设备上配置端口镜像,必须先在层次结构级别配置 forwarding-options [edit] 和interfaces。
您必须配置该 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
配置一个名为
watch-employee的防火墙过滤器,其中包含一个术语,用于匹配发送到 Web 并将其发送到端口镜像实例employee-web-monitor的流量。无需复制进出公司子网(目标地址或源地址192.0.2.16/28)的流量,因此请在流量到达将 Web 流量发送到实例的术语之前创建另一个术语以接受该流量:[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 的员工流量。
拓扑结构
在此示例中:
接口,
ge-0/0/0ge-0/0/1是连接到员工计算机的第 2 层接口。接口
ge-0/0/2是连接到另一台交换机的第 2 层接口。拓扑中的所有交换机上均配置了 VLAN
remote-analyzer,以承载镜像流量。
除了执行此处所述的配置步骤外,还必须在用于将源交换机(此配置中的交换机)连接到监控站所连接的其他交换机上配置分析器 VLAN(remote-analyzer 在本例中)。
镜像所有员工流量以进行远程分析
过程
CLI 快速配置
要快速配置示例的此部分,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,更改任何必要的详细信息以匹配您的网络配置,然后将命令复制粘贴到层次结构级别的 edit CLI 中:
[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
在将此交换机连接到监控工作站的交换机上配置
remote-analyzerVLAN。
结果
检查配置结果:
[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 快速配置
要快速配置示例的此部分,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,更改任何必要的详细信息以匹配您的网络配置,然后将命令复制粘贴到层次结构级别的 edit CLI 中:
[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
配置一个名为
watch-employee的防火墙过滤器,以匹配发送到 Web 并将其发送到分析器的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
在将此交换机连接到监控工作站的交换机上配置
remote-analyzerVLAN。
结果
检查配置结果:
[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-monitoremployee-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。