配置数据路径调试和跟踪选项
了解 SRX 系列设备的数据路径调试
数据路径调试或端到端调试支持在数据包处理路径上的多个处理单元提供跟踪和调试。数据包过滤器可以在对生产系统影响最小的情况下执行。
在 SRX 系列防火墙上,数据包会经历一系列事件,涉及从入口到出口处理的不同组件。
使用数据路径调试功能,您可以在处理路径上的不同数据点进行跟踪和调试(捕获数据包)。数据包处理路径中可用的事件包括:NP 入口、负载平衡线程 (LBT)、jexec、数据包排序线程 (POT) 和 NP 出口。如果为某个模块设置了安全流跟踪标志,您还可以启用流模块跟踪。
在每个事件中,您可以指定四个操作(计数、数据包转储、数据包摘要和跟踪)中的任何一个。数据路径调试提供过滤器来定义要捕获的数据包,并且仅跟踪匹配的数据包。数据包过滤器可以根据逻辑接口、协议、源 IP 地址前缀、源端口、目标 IP 地址前缀和目标端口过滤掉数据包。
SRX4600、SRX5400、SRX5600和SRX5800支持 数据路径调试。
若要启用端到端调试,必须执行以下步骤:
定义捕获文件并指定最大捕获大小。
定义数据包过滤器以根据要求仅跟踪特定类型的流量。
定义操作配置文件,指定处理路径上捕获数据包的位置(例如,LBT 或 NP 入口)。
启用数据路径调试。
捕获流量。
禁用数据路径调试。
查看或分析报告。
端口和接口选项的数据包过滤行为如下所示:
如果仅 port 指定了数据包过滤器,则会跟踪 IPv4 和 IPv6 流量。
数据包过滤器将跟踪 IPv4、IPV6 和非 IP 流量(如果仅 interface 指定)。
了解使用跟踪选项进行安全调试
Junos OS 跟踪功能允许应用程序将安全调试信息写入文件。此文件中显示的信息基于您设置的条件。您可以使用此信息来分析安全应用程序问题。
trace 函数以分布式方式运行,每个线程写入其自己的跟踪缓冲区。然后将这些跟踪缓冲区收集到某一点,对其进行排序并写入跟踪文件。跟踪消息使用进程间通信 (IPC) 协议传递。跟踪消息的优先级低于控制协议数据包(如 BGP、OSPF 和 IKE)的优先级,因此传递不被视为可靠。
了解使用跟踪选项进行流调试
对于流跟踪选项,您可以使用 、 destination-prefix、 source-portinterfaceprotocol和 source-prefix的组合来destination-port定义数据包过滤器。如果为某个模块设置了安全流跟踪标志,则与特定数据包过滤器匹配的数据包将触发流跟踪并将调试信息写入跟踪文件。
调试数据路径(CLI 过程)
SRX5400、SRX5600 和 SRX5800 上 支持数据路径调试。
要配置设备以进行数据路径调试,请执行以下操作:
设置流调试跟踪选项(CLI 过程)
以下示例显示了可以使用 设置 security flow traceoptions
的选项。
要匹配 filter1 数据包过滤器的 imap 目标端口,请使用以下语句:
[edit] user@host# set security flow traceoptions packet-filter filter1 destination-port imap
要为 filter1 数据包过滤器设置 1.2.3.4 目标 IPv4 前缀地址,请使用以下语句:
[edit] user@host# set security flow traceoptions packet-filter filter1 destination-prefix 1.2.3.4
要为 filter1 数据包过滤器设置 fxp0 逻辑接口,请使用以下语句:
[edit] user@host# set security flow traceoptions packet-filter filter1 interface fxp0
要匹配 filter1 数据包过滤器的 TCP IP 协议,请使用以下语句:
[edit] user@host# set security flow traceoptions packet-filter filter1 protocol tcp
要匹配 filter1 数据包过滤器的 HTTP 源端口,请使用以下语句:
[edit] user@host# set security flow traceoptions packet-filter filter1 source-port http
要为 filter1 数据包过滤器设置 5.6.7.8 IPv4 前缀地址,请使用以下语句:
[edit] user@host# set security flow traceoptions packet-filter filter1 source-prefix 5.6.7.8
设置安全跟踪选项(CLI 过程)
使用以下配置语句在 CLI 配置编辑器中配置安全跟踪选项。
要禁用远程跟踪,请输入以下语句:
[edit] user@host# set security traceoptions no-remote-trace
要将跟踪消息写入本地文件,请输入以下语句。系统将跟踪文件 /var/log/ 保存在目录中。
[edit] user@host# set security traceoptions use-local-files
要指定跟踪文件的名称,请输入以下语句。有效值范围为 1 到 1024 个字符。名称不能包含空格、/ 或 % 字符。默认文件名为安全性。
[edit] user@host# set security traceoptions file filename
若要指定可以累积的最大跟踪文件数,请输入以下语句。有效值范围为 2 到 1000。默认值为 3。
[edit] user@host# set security traceoptions file files 3
要指定在将信息记录到文件时希望系统使用的匹配标准,请输入以下语句。输入正则表达式。接受通配符 (*) 字符。
[edit] user@host# set security traceoptions file match *thread
要允许任何用户读取跟踪文件,
world-readable
请输入语句。否则,请输入no-world-readable
语句。[edit] user@host# set security traceoptions file world-readable user@host# set security traceoptions file no-world-readable
若要指定跟踪文件可以增长到的最大大小,请输入以下语句。文件达到指定大小后,将其压缩并重命名 filename0.gz,下一个文件命名 filename为 1.gz,依此类推。有效值范围为 10240 到 1,073,741,824。
[edit] user@host# set security traceoptions file size 10240
若要打开跟踪选项并执行多个跟踪操作,请设置以下标志。
[edit] user@host# set security traceoptions flag all user@host# set security traceoptions flag compilation user@host# set security traceoptions flag configuration user@host# set security traceoptions flag routing-socket
要指定这些跟踪选项设置适用或不适用的组,请输入以下语句:
[edit] user@host# set security traceoptions apply-groups value user@host# set security traceoptions apply-groups-except value
显示日志和跟踪文件
输入命令以 monitor start
显示对系统日志和跟踪文件的实时添加:
user@host> monitor start filename
当设备将记录添加到 指定的 filename
文件时,该记录将显示在屏幕上。例如,如果已配置名为system-log
(通过在 [edit system
] 层次结构级别包含syslog
语句),则可以输入monitor start system-log
命令以显示添加到系统日志中的记录。
要显示正在监视的文件列表,请输入 monitor list
命令。要停止显示指定文件的记录,请输入 monitor stop filename
命令。
显示安全跟踪选项的输出
目的
显示安全跟踪选项的输出。
操作
使用该 show security traceoptions
命令显示跟踪文件的输出。例如:
[edit] user@host # show security traceoptions file usp_trace user@host # show security traceoptions flag all user@host # show security traceoptions rate-limit 888
此示例的输出如下所示:
Apr 11 16:06:42 21:13:15.750395:CID-906489336:FPC-01:PIC-01:THREAD_ID-01:PFE:now update 0x3607edf8df8in 0x3607e8d0 Apr 11 16:06:42 21:13:15.874058:CID-1529687608:FPC-01:PIC-01:THREAD_ID-01:CTRL:Enter Function[util_ssam_handler] Apr 11 16:06:42 21:13:15.874485:CID-00:FPC-01:PIC-01:THREAD_ID-01:CTRL:default1: Rate limit changed to 888 Apr 11 16:06:42 21:13:15.874538:CID-00:FPC-01:PIC-01:THREAD_ID-01:CTRL:default1: Destination ID set to 1 Apr 11 16:06:42 21:13:15.874651:CID-00:FPC-01:PIC-01:THREAD_ID-01:CTRL:default2: Rate limit changed to 888 Apr 11 16:06:42 21:13:15.874832:CID-00:FPC-01:PIC-01:THREAD_ID-01:CTRL:default2: Destination ID set to 1 Apr 11 16:06:42 21:13:15.874942:CID-00:FPC-01:PIC-01:THREAD_ID-01:CTRL:default3: Rate limit changed to 888 Apr 11 16:06:42 21:13:15.874997:CID-00:FPC-01:PIC-01:THREAD_ID-01:CTRL:default3: Destination ID set to 1
显示组播跟踪操作
要监控和显示组播跟踪操作,请输入 mtrace monitor
以下命令:
user@host> mtrace monitor
Mtrace query at Apr 21 16:00:54 by 192.1.30.2, resp to 224.0.1.32, qid 2a83aa packet from 192.1.30.2 to 224.0.0.2 from 192.1.30.2 to 192.1.4.1 via group 224.1.1.1 (mxhop=60) Mtrace query at Apr 21 16:00:57 by 192.1.30.2, resp to 224.0.1.32, qid 25dc17 packet from 192.1.30.2 to 224.0.0.2 from 192.1.30.2 to 192.1.4.1 via group 224.1.1.1 (mxhop=60) Mtrace query at Apr 21 16:01:00 by 192.1.30.2, resp to same, qid 20e046 packet from 192.1.30.2 to 224.0.0.2 from 192.1.30.2 to 192.1.4.1 via group 224.1.1.1 (mxhop=60) Mtrace query at Apr 21 16:01:10 by 192.1.30.2, resp to same, qid 1d25ad packet from 192.1.30.2 to 224.0.0.2 from 192.1.30.2 to 192.1.4.1 via group 224.1.1.1 (mxhop=60)
此示例仅 mtrace
显示查询。但是,当设备捕获 mtrace
响应时,显示类似,但也会显示完整的 mtrace
响应(与命令输出中显示的 mtrace from-source
完全一样)。
表 1 汇总显示的输出字段。
田 |
Description |
---|---|
|
|
|
发出查询的主机的 IP 地址。 |
|
|
|
|
|
|
|
|
|
|
|
|
显示设备列表
要显示设备与指定目标主机之间的设备列表,请使用以下语法输入 traceroute
命令:
user@host> traceroute host <interface interface-name> <as-number-lookup> <bypass-routing> <gateway address> <inet | inet6> <no-resolve> <routing-instance routing-instance-name> <source source-address> <tos number> <ttl number> <wait seconds>
表 2traceroute
介绍了命令选项。
选项 |
Description |
---|---|
|
将跟踪路由数据包发送到您指定的主机名或 IP 地址。 |
|
(可选)在您指定的接口上发送路由跟踪数据包。如果不包括此选项,则会在所有接口上发送跟踪路由数据包。 |
|
(可选)显示设备和目标主机之间每个中间跃点的自治系统 (AS) 编号。 |
|
(可选)绕过路由表,仅将 traceroute 数据包发送到直连接口上的主机。如果主机不在直接连接的接口上,则会返回错误消息。 使用此选项可通过没有路由的接口显示到本地系统的路由。 |
|
(可选)使用您指定的路由网关。 |
|
(可选)强制将跟踪路由数据包强制发送到 IPv4 目标。 |
|
(可选)强制将路由跟踪数据包强制发送至 IPv6 目标。 |
|
(可选)禁止显示沿路径的跃点的主机名。 |
|
(可选)使用您为路由跟踪指定的路由实例。 |
|
(可选)在跟踪路由数据包中使用您指定的源地址。 |
|
(可选)设置路由跟踪数据包的 IP 报头中的服务类型 (TOS) 值。指定从 |
|
(可选)设置路由跟踪数据包的生存时间 (TTL) 值。指定从 |
|
(可选)设置等待响应的最长时间。 |
若要退出 traceroute
该命令,请按 Ctrl-C。
下面是命令的示例 traceroute
输出:
user@host> traceroute host2
traceroute to 173.24.232.66 (172.24.230.41), 30 hops max, 40 byte packets 1 173.18.42.253 (173.18.42.253) 0.482 ms 0.346 ms 0.318 ms 2 host4.site1.net (173.18.253.5) 0.401 ms 0.435 ms 0.359 ms 3 host5.site1.net (173.18.253.5) 0.401 ms 0.360 ms 0.357 ms 4 173.24.232.65 (173.24.232.65) 0.420 ms 0.456 ms 0.378 ms 5 173.24.232.66 (173.24.232.66) 0.830 ms 0.779 ms 0.834 ms
显示中的字段与 J-Web 路由跟踪诊断工具显示的字段相同。
示例:在 SRX 系列设备上配置端到端调试
此示例说明如何在高端 SRX 系列防火墙 上配置数据包捕获,以及如何在使用 SRX5K-MPC 的 SRX 系列防火墙上启用端到端调试。
要求
此示例使用以下硬件和软件组件:
安装了 100 千兆以太网 CFP 收发器的 SRX5K-MPC 的SRX5600设备
适用于 SRX 系列防火墙的 Junos OS 12.1X47-D15 或更高版本
准备工作:
请参阅 了解 SRX 系列设备的数据路径调试。
配置此功能之前,不需要除设备初始化之外的特殊配置。
概述
数据路径调试通过在数据包处理路径上的多个处理单元提供跟踪和调试来增强故障排除功能。使用数据路径调试功能,您可以在处理路径上的不同数据点进行跟踪和调试(捕获数据包)。在每个事件中,您可以指定操作(计数、数据包转储、数据包摘要和跟踪),并且可以设置过滤器来定义要捕获的数据包。
在此示例中,您将定义流量过滤器,然后应用操作配置文件。操作配置文件指定处理单元上的各种操作。入口和出口被指定为处理路径上的位置,以捕获传入和传出流量的数据。
接下来,在操作模式下启用数据路径调试,最后查看数据捕获报告。
SRX5400、SRX5600 和 SRX5800 上 支持数据路径调试。
配置
程序
CLI 快速配置
要快速配置此示例,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,更改详细信息,以便与网络配置匹配,将命令复制并粘贴到 [edit]
层级的 CLI 中,然后从配置模式进入 commit
。
set security datapath-debug traceoptions file e2e.trace size 10m set security datapath-debug capture-file e2e.pcap format pcap set security datapath-debug maximum-capture-size 1500 set security datapath-debug capture-file files 10 set security datapath-debug action-profile profile-1 preserve-trace-order set security datapath-debug action-profile profile-1 record-pic-history set security datapath-debug action-profile profile-1 event np-ingress trace set security datapath-debug action-profile profile-1 event np-ingress count set security datapath-debug action-profile profile-1 event np-ingress packet-summary set security datapath-debug action-profile profile-1 event np-egress trace set security datapath-debug action-profile profile-1 event np-egress count set security datapath-debug action-profile profile-1 event np-egress packet-summary
分步过程
下面的示例要求您在各个配置层级中进行导航。有关如何执行此操作的说明,请参阅 Junos OS CLI 用户指南 中的在配置模式下使用 CLI 编辑器 。
要配置数据路径调试,请执行以下操作:
编辑数据包处理路径上多个处理单元的安全数据路径调试选项:
[edit] user@host# edit security datapath-debug
启用捕获文件、文件格式、文件大小和文件数。
[edit security datapath-debug] user@host# set traceoptions file e2e.trace size 10m user@host# set capture-file e2e.pcap format pcap; user@host# set maximum-capture-size 1500 user@host# set capture-file files 10
为操作配置文件配置操作配置文件、事件类型和操作。
[edit security datapath-debug] user@host# set action-profile profile-1 preserve-trace-order user@host# set action-profile profile-1 record-pic-history user@host# set action-profile profile-1 event np-ingress trace user@host# set action-profile profile-1 event np-ingress count user@host# set action-profile profile-1 event np-ingress packet-summary user@host# set action-profile profile-1 event np-egress trace user@host# set action-profile profile-1 event np-egress count user@host# set action-profile profile-1 event np-egress packet-summary
结果
在配置模式下,输入 show security datapath-debug
命令以确认您的配置。如果输出未显示预期的配置,请重复此示例中的配置说明,以便进行更正。
traceoptions { file e2e.trace size 10m; } capture-file e2e.pcap format pcap; maximum-capture-size 1500; capture-file files 10; action-profile { profile-1 { preserve-trace-order; record-pic-history; event np-ingress { trace; packet-summary; packet-dump; } event np-egress { trace; packet-summary; packet-dump; } } }
如果完成设备配置,请从配置模式输入 commit
。
示例:为数据路径调试配置数据包捕获
此示例说明如何配置数据包捕获以监控通过设备的流量。然后,数据包捕获会将数据包转储为 PCAP 文件格式,以便稍后由 tcpdump 实用程序进行检查。
要求
开始之前,请参阅调试数据路径(CLI 过程)。
概述
定义过滤器以过滤流量;然后将操作配置文件应用于过滤后的流量。操作配置文件指定处理单元上的各种操作。数据包转储是受支持的操作之一,它将数据包发送到路由引擎,并以专有形式存储,以便使用命令读取 show security datapath-debug capture
。
配置
程序
CLI 快速配置
要快速配置此示例,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,更改详细信息,以便与网络配置匹配,将命令复制并粘贴到 [edit]
层级的 CLI 中,然后从配置模式进入 commit
。
set security datapath-debug capture-file my-capture set security datapath-debug capture-file format pcap set security datapath-debug capture-file size 1m set security datapath-debug capture-file files 5 set security datapath-debug maximum-capture-size 400 set security datapath-debug action-profile do-capture event np-ingress packet-dump set security datapath-debug packet-filter my-filter action-profile do-capture set security datapath-debug packet-filter my-filter source-prefix 1.2.3.4/32
分步过程
下面的示例要求您在各个配置层级中进行导航。有关如何执行此操作的说明,请参阅 Junos OS CLI 用户指南中的在配置模式下使用 CLI 编辑器。
要配置数据包捕获:
编辑数据包处理路径上多个处理单元的安全数据路径调试选项:
[edit] user@host# edit security datapath-debug
启用捕获文件、文件格式、文件大小和文件数。大小数字限制捕获文件的大小。达到限制大小后,如果指定了文件编号,则捕获文件将轮换为 文件名 x,其中 x 自动递增,直到到达指定的索引,然后返回到零。如果未指定文件索引,则在达到大小限制后将丢弃数据包。默认大小为 512 KB。
[edit security datapath-debug] user@host# set capture-file my-capture format pcap size 1m files 5 [edit security datapath-debug] user@host# set maximum-capture-size 400
启用操作配置文件并设置事件。将操作配置文件设置为执行捕获,将事件类型设置为 np 入口:
[edit security datapath-debug] user@host# edit action-profile do-capture [edit security datapath-debug action-profile do-capture] user@host# edit event np-ingress
为操作配置文件启用数据包转储:
[edit security datapath-debug action-profile do-capture event np-ingress] user@host# set packet-dump
启用数据包过滤器、操作和过滤器选项。数据包过滤器设置为 my-filter,操作配置文件设置为 do-capture,过滤器选项设置为源前缀 1.2.3.4/32。
[edit security datapath-debug] user@host# set security datapath-debug packet-filter my-filter action-profile do-capture
[edit security datapath-debug] user@host# set security datapath-debug packet-filter my-filter source-prefix 1.2.3.4/32
结果
在配置模式下,输入 show security datapath-debug
命令以确认您的配置。如果输出未显示预期的配置,请重复此示例中的配置说明,以便进行更正。
security { datapath-debug { capture-file { my-capture format pcap size 1m files 5; } } maximum-capture-size 100; action-profile do-capture { event np-ingress { packet-dump } } packet-filter my-filter { source-prefix 1.2.3.4/32 action-profile do-capture } }
如果完成设备配置,请从配置模式输入 commit
。
验证
确认配置工作正常。
验证数据包捕获
目的
验证数据包捕获是否正常工作。
操作
在操作模式下,输入 request security datapath-debug capture start
命令以启动数据包捕获,并输入 request security datapath-debug capture stop
命令以停止数据包捕获。
要查看结果,请在 CLI 操作模式下访问本地 UNIX 外壳并导航到目录 /var/log/my-capture。可以使用 tcpdump 实用程序读取结果。
验证数据路径调试捕获
目的
验证数据路径调试捕获文件的详细信息。
操作
在操作模式下,输入 show security datapath-debug capture
命令。
user@host>show security datapath-debug capture
完成故障排除后,请确保删除或停用所有 traceoptions 配置(不限于流跟踪选项)和完整的安全数据路径调试配置节。如果任何调试配置保持活动状态,它们将继续使用设备的 CPU 和内存资源。
启用数据路径调试
程序
分步过程
配置数据路径调试后,必须在设备上从操作模式启动该过程。
启用数据路径调试。
user@host> request security datapath-debug capture start
datapath-debug capture started on file datapcap
在验证配置和查看报告之前,必须禁用数据路径调试。
user@host> request security datapath-debug capture stop
datapath-debug capture succesfully stopped, use show security datapath-debug capture to view
注:捕获完数据后,必须停止调试过程。如果尝试在不停止调试过程的情况下打开捕获的文件,则无法通过任何第三方软件(例如,tcpdump 和 wireshark)打开获取的文件。
验证
确认配置工作正常。
验证数据路径调试数据包捕获详细信息
目的
通过启用数据路径调试配置来验证捕获的数据。
操作
在操作模式下,输入 show security datapath-debug capture
命令。
Packet 8, len 152: (C2/F2/P0/SEQ:57935:np-ingress) 00 10 db ff 10 02 00 30 48 83 8d 4f 08 00 45 00 00 54 00 00 40 00 40 01 9f c7 c8 07 05 69 c8 08 05 69 08 00 91 1f 8f 03 2a a2 ae 66 85 53 8c 7d 02 00 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 Packet 9, len 152: (C2/F2/P0/SEQ:57935:np-egress) 00 30 48 8d 1a bf 00 10 db ff 10 03 08 00 45 00 00 54 00 00 40 00 3f 01 a0 c7 c8 07 05 69 c8 08 05 69 08 00 91 1f 8f 03 2a a2 ae 66 85 53 8c 7d 02 00 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37....
为简洁起见, show
命令输出被截断以仅显示几个示例。其他示例已替换为省略号 (...)。
要查看结果,请在 CLI 操作模式下访问本地 UNIX 外壳并导航到目录 /var/log/<file-name>。可以使用该 tcpdump
实用程序读取结果。
user@host>start shell %tcpdump -nr/var/log/e2e.pcap
21:50:04.288767 C0/F3 event:1(np-ingress) SEQ:1 IP 192.168.14.2 > 192.168.13.2: ICMP echo request, id 57627, seq 0, length 64 21:50:04.292590 C0/F3 event:2(np-egress) SEQ:1 IP 192.168.14.2 > 192.168.13.2: ICMP echo request, id 57627, seq 0, length 64 1:50:04.295164 C0/F3 event:1(np-ingress) SEQ:2 IP 192.168.13.2 > 192.168.14.2: ICMP echo reply, id 57627, seq 0, length 64 21:50:04.295284 C0/F3 event:2(np-egress) SEQ:2 IP 192.168.13.2 > 192.168.14.2: ICMP echo reply, id 57627, seq 0, length 64
如果已完成数据路径调试故障排除,请删除所有 traceoptions
(不限于流跟踪选项)和完整的数据路径调试配置,包括用于数据包捕获(数据包转储)的数据路径调试配置,该配置需要手动启动/停止。如果调试配置的任何部分保持活动状态,它将继续使用设备的资源(CPU/内存)。