示例:配置过滤器以对 IP 选项数据包进行计数
此示例说明如何使用无状态防火墙过滤器对单个 IP 选项数据包进行计数:
要求
此示例使用 MX 系列路由器上的 10 千兆以太网模块化端口集中器 (MPC)、60 千兆以太网 MPC、60 千兆队列以太网 MPC 或 60 千兆以太网增强型排队 MPC 上的接口。通过此接口,您可以应用 IPv4 防火墙过滤器(标准过滤器或服务过滤器),该过滤器可以对与特定 ip-option
值匹配的数据包使用 count
、 log
和非syslog
终止操作,而无需同时使用discard
终止操作。
配置此示例之前,不需要除设备初始化之外的特殊配置。
概述
在此示例中,您使用无状态防火墙过滤器对 IP 选项数据包进行计数,但不阻止任何流量。此外,过滤器还会记录具有松散或严格源路由的数据包。
IP 选项标头字段仅在 IPv4 标头中是可选字段。ip-options
仅标准无状态防火墙过滤器和服务过滤器支持和ip-options-except
匹配条件。
在 M 和 T 系列路由器上,防火墙过滤器无法按选项类型和接口对数据包进行计数 ip-options
。有限的解决方法是使用该命令查看show pfe statistics ip options
ip-options
每个数据包转发引擎 (PFE) 的统计信息。有关示例输出,请参阅 显示 pfe 统计信息 ip 。
配置
下面的示例要求您在各个配置层级中进行导航。有关导航 CLI 的信息,请参见 在配置模式下使用 CLI 编辑器。
要配置此示例,请执行以下操作:
CLI 快速配置
要快速配置此示例,请将以下配置命令复制到文本文件中,删除所有换行符,然后将命令粘贴到层次结构级别的 CLI [edit]
中。
set firewall family inet filter ip_options_filter term match_strict_source from ip-options strict-source-route set firewall family inet filter ip_options_filter term match_strict_source then count strict_source_route set firewall family inet filter ip_options_filter term match_strict_source then log set firewall family inet filter ip_options_filter term match_strict_source then accept set firewall family inet filter ip_options_filter term match_loose_source from ip-options loose-source-route set firewall family inet filter ip_options_filter term match_loose_source then count loose_source_route set firewall family inet filter ip_options_filter term match_loose_source then log set firewall family inet filter ip_options_filter term match_loose_source then accept set firewall family inet filter ip_options_filter term match_record from ip-options record-route set firewall family inet filter ip_options_filter term match_record then count record_route set firewall family inet filter ip_options_filter term match_record then accept set firewall family inet filter ip_options_filter term match_timestamp from ip-options timestamp set firewall family inet filter ip_options_filter term match_timestamp then count timestamp set firewall family inet filter ip_options_filter term match_timestamp then accept set firewall family inet filter ip_options_filter term match_router_alert from ip-options router-alert set firewall family inet filter ip_options_filter term match_router_alert then count router_alert set firewall family inet filter ip_options_filter term match_router_alert then accept set firewall family inet filter ip_options_filter term match_all then accept set interfaces ge-0/0/1 unit 0 family inet address 10.1.2.3/30 set interfaces ge-0/0/1 unit 0 family inet filter input ip_options_filter
配置无状态防火墙过滤器
分步过程
要配置无状态防火墙过滤器 ip_option_filter
:
创建无状态防火墙过滤器
ip_option_filter
。[edit] user@host# edit firewall family inet filter ip_options_filter
使用 IP 可选标头字段配置
strict_source_route
第一个术语以计数、记录和接受数据包。[edit firewall family inet filter ip_option_filter] user@host# set term match_strict_source from ip-options strict_source_route user@host# set term match_strict_source then count strict_source_route user@host# set term match_strict_source then log user@host# set term match_strict_source then accept
配置下一个术语以计数、记录和接受带有 IP 可选标头字段的
loose-source-route
数据包。[edit firewall family inet filter ip_option_filter] user@host# set term match_loose_source from ip-options loose-source-route user@host# set term match_loose_source then count loose_source_route user@host# set term match_loose_source then log user@host# set term match_loose_source then accept
配置下一个术语以计数并接受带有 IP 可选标头字段的
record-route
数据包。[edit firewall family inet filter ip_option_filter] user@host# set term match_record from ip-options record-route user@host# set term match_record then count record_route user@host# set term match_record then accept
配置下一个术语以计数并接受带有 IP 可选标头字段的
timestamp
数据包。[edit firewall family inet filter ip_option_filter] user@host# set term match_timestamp from ip-options timestamp user@host# set term match_timestamp then count timestamp user@host# set term match_timestamp then accept
配置下一个术语以计数并接受带有 IP 可选标头字段的
router-alert
数据包。[edit firewall family inet filter ip_option_filter] user@host# set term match_router_alert from ip-options router-alert user@host# set term match_router_alert then count router_alert user@host# set term match_router_alert then accept
创建最后一个术语以接受任何数据包而不增加任何计数器。
[edit firewall family inet filter ip_option_filter] user@host# set term match_all then accept
将无状态防火墙过滤器应用于逻辑接口
分步过程
要将无状态防火墙过滤器应用于逻辑接口,请执行以下操作:
配置要应用无状态防火墙过滤器的逻辑接口。
[edit] user@host# edit interfaces ge-0/0/1 unit 0 family inet
配置逻辑接口的接口地址。
[edit interfaces ge-0/0/1 unit 0 family inet] user@host# set address 10.1.2.3/30
将无状态防火墙过滤器应用于逻辑接口。
[edit interfaces ge-0/0/1 unit 0 family inet] user@host# set filter input ip_options_filter
确认并提交候选配置
分步过程
要确认并提交候选配置,请执行以下操作:
通过输入
show firewall
配置模式命令确认无状态防火墙过滤器的配置。如果命令输出未显示预期的配置,请重复此示例中的说明以更正配置。[edit] user@host# show firewall family inet { filter ip_options_filter { term match_strict_source { from { ip-options strict-source-route; } then { count strict_source_route; log; accept; } } term match_loose_source { from { ip-options loose-source-route; } then { count loose_source_route; log; accept; } } term match_record { from { ip-options record-route; } then { count record_route; accept; } } term match_timestamp { from { ip-options timestamp; } then { count timestamp; accept; } } term match_router_alert { from { ip-options router-alert; } then { count router_alert; accept; } } term match_all { then accept; } } }
通过输入
show interfaces
配置模式命令确认接口的配置。如果命令输出未显示预期的配置,请重复此示例中的说明以更正配置。[edit] user@host# show interfaces ge-0/0/1 { unit 0 { family inet { filter { input ip_option_filter; } address 10.1.2.3/30; } } }
如果完成设备配置,请提交候选配置。
[edit] user@host# commit
验证
要确认配置工作正常,请输入 show firewall filter ip_option_filter
操作模式命令。还可以使用以下形式的命令分别显示日志和单个计数器:
show firewall counter strict_source_route
show firewall counter loose_source_route
show firewall counter record_route
show firewall counter timestamp
show firewall counter router_alert
show firewall log