示例:在逻辑系统上配置基于过滤器的转发
此示例说明如何在逻辑系统中配置基于过滤器的转发。过滤器对数据包进行分类,以确定其在入口路由设备中的转发路径。
要求
在此示例中,不需要除设备初始化之外的特殊配置。
概述
IP 版本 4 (IPv4) 和 IP 版本 6 (IPv6) 支持基于过滤器的转发。
当客户拥有由不同 ISP 提供的互联网连接但共享一个公共访问层时,请使用基于过滤器的转发来选择服务提供商。使用共享介质(如电缆调制解调器)时,公共接入层上的机制会查看第 2 层或第 3 层地址,并区分客户。当使用第 2 层交换机和单个路由器的组合来实施公共接入层时,您可以使用基于过滤器的转发。
使用基于过滤器的转发时,接口上接收的所有数据包都会被考虑在内。每个数据包都通过具有匹配条件的过滤器。如果满足过滤器的匹配条件,并且您已经创建了路由实例,则基于过滤器的转发将应用于数据包。数据包根据路由实例中指定的下一跃点进行转发。对于静态路由,下一跃点可以是特定的 LSP。
配置了基于过滤器的转发 (FBF) 的接口不支持源类用法过滤器匹配和单播反向路径转发检查。
要配置基于过滤器的转发,请执行以下操作:
在入口路由器或交换机上创建匹配过滤器。要指定匹配筛选器,请在层次结构级别包含语句。
filter filter-name
[edit firewall]
将通过过滤器的数据包与一组规则进行比较,以对其进行分类并确定其在一组数据包中的成员身份。分类后,数据包将以过滤器描述语言转发到在接受操作中指定的路由表。然后,路由表将数据包转发到与表中的目标地址条目对应的下一跃点。创建路由实例,用于指定数据包转发到的路由表,以及在 OR 层次结构级别将数据包转发到的目标。
[edit routing-instances]
[edit logical-systems logical-system-name routing-instances]
例如:[edit] routing-instances { routing-table-name1 { instance-type forwarding; routing-options { static { route 0.0.0.0/0 nexthop 10.0.0.1; } } } routing-table-name2 { instance-type forwarding; routing-options { static { route 0.0.0.0/0 nexthop 10.0.0.2; } } } }
创建一个路由表组,用于将接口路由添加到基于过滤器的转发 (FBF) 中使用的转发路由实例以及默认路由实例 。
inet.0
这部分配置将路由实例中安装的路由解析为直接连接到该接口上的下一跃点。在或层次结构级别创建路由表组。[edit routing-options]
[edit logical-systems logical-system-name routing-options]
指定 为接口路由导入到的路由实例之一。inet.0
如果未指定默认实例,则接口路由不会导入到默认路由实例 中。inet.0
此示例显示了一个数据包过滤器,该过滤器根据数据包的源地址将客户流量定向到域 SP 1 或 SP 2 中的下一跃点路由器。
如果数据包的源地址已分配给 SP 1 客户,则使用 sp1-route-table.inet.0 路由表进行基于目标的转发。如果数据包的源地址分配给了 SP 2 客户,则使用 sp2-route-table.inet.0 路由表进行基于目标的转发。如果数据包不符合上述任一条件,过滤器将接受数据包,并使用标准 inet.0 路由表进行基于目标的转发。
使基于过滤器的转发在逻辑系统中起作用的一种方法是在接收数据包的逻辑系统上配置防火墙过滤器。另一种方法是在主路由器上配置防火墙过滤器,然后在防火墙过滤器中引用逻辑系统。此示例使用第二种方法。特定路由实例在逻辑系统中配置。由于每个路由实例都有自己的路由表,因此您还必须引用防火墙过滤器中的路由实例。语法如下所示:
[edit firewall filter filter-name term term-name] user@host# set then logical-system logical-system-name routing-instance routing-instance-name
拓扑
图 1 显示了此示例中使用的拓扑。
在逻辑系统 P1 上,输入过滤器对从逻辑系统 PE3 和逻辑系统 PE4 接收的数据包进行分类。数据包基于源地址进行路由。源地址在 10.1.1.0/24 和 10.1.2.0/24 网络中的数据包将路由到逻辑系统 PE1。源地址在 10.2.1.0/24 和 10.2.2.0/24 网络中的数据包将路由到逻辑系统 PE2。
要建立连接,必须在所有接口上配置 OSPF。出于演示目的,在路由设备上配置环路接口地址以表示云中的网络。
该 部分显示拓扑中所有设备的完整配置。CLI 快速配置和部分显示了入口路由设备(逻辑系统 P1)的分步配置。在逻辑系统 P1 上配置路由实例在主路由器上配置防火墙过滤器
配置
CLI 快速配置
要快速配置此示例,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,更改与您的网络配置匹配所需的任何详细信息,然后将命令复制并粘贴到层次结构级别的 CLI 中。[edit]
set firewall filter classify-customers term sp1-customers from source-address 10.1.1.0/24 set firewall filter classify-customers term sp1-customers from source-address 10.1.2.0/24 set firewall filter classify-customers term sp1-customers then log set firewall filter classify-customers term sp1-customers then logical-system P1 routing-instance sp1-route-table set firewall filter classify-customers term sp2-customers from source-address 10.2.1.0/24 set firewall filter classify-customers term sp2-customers from source-address 10.2.2.0/24 set firewall filter classify-customers term sp2-customers then log set firewall filter classify-customers term sp2-customers then logical-system P1 routing-instance sp2-route-table set firewall filter classify-customers term default then accept set logical-systems P1 interfaces lt-1/2/0 unit 10 encapsulation ethernet set logical-systems P1 interfaces lt-1/2/0 unit 10 peer-unit 9 set logical-systems P1 interfaces lt-1/2/0 unit 10 family inet filter input classify-customers set logical-systems P1 interfaces lt-1/2/0 unit 10 family inet address 172.16.0.10/30 set logical-systems P1 interfaces lt-1/2/0 unit 13 encapsulation ethernet set logical-systems P1 interfaces lt-1/2/0 unit 13 peer-unit 14 set logical-systems P1 interfaces lt-1/2/0 unit 13 family inet address 172.16.0.13/30 set logical-systems P1 interfaces lt-1/2/0 unit 17 encapsulation ethernet set logical-systems P1 interfaces lt-1/2/0 unit 17 peer-unit 18 set logical-systems P1 interfaces lt-1/2/0 unit 17 family inet address 172.16.0.17/30 set logical-systems P1 protocols ospf rib-group fbf-group set logical-systems P1 protocols ospf area 0.0.0.0 interface all set logical-systems P1 protocols ospf area 0.0.0.0 interface fxp0.0 disable set logical-systems P1 routing-instances sp1-route-table instance-type forwarding set logical-systems P1 routing-instances sp1-route-table routing-options static route 0.0.0.0/0 next-hop 172.16.0.13 set logical-systems P1 routing-instances sp2-route-table instance-type forwarding set logical-systems P1 routing-instances sp2-route-table routing-options static route 0.0.0.0/0 next-hop 172.16.0.17 set logical-systems P1 routing-options rib-groups fbf-group import-rib inet.0 set logical-systems P1 routing-options rib-groups fbf-group import-rib sp1-route-table.inet.0 set logical-systems P1 routing-options rib-groups fbf-group import-rib sp2-route-table.inet.0 set logical-systems P2 interfaces lt-1/2/0 unit 2 encapsulation ethernet set logical-systems P2 interfaces lt-1/2/0 unit 2 peer-unit 1 set logical-systems P2 interfaces lt-1/2/0 unit 2 family inet address 172.16.0.2/30 set logical-systems P2 interfaces lt-1/2/0 unit 6 encapsulation ethernet set logical-systems P2 interfaces lt-1/2/0 unit 6 peer-unit 5 set logical-systems P2 interfaces lt-1/2/0 unit 6 family inet address 172.16.0.6/30 set logical-systems P2 interfaces lt-1/2/0 unit 9 encapsulation ethernet set logical-systems P2 interfaces lt-1/2/0 unit 9 peer-unit 10 set logical-systems P2 interfaces lt-1/2/0 unit 9 family inet address 172.16.0.9/30 set logical-systems P2 protocols ospf area 0.0.0.0 interface all set logical-systems P2 protocols ospf area 0.0.0.0 interface fxp0.0 disable set logical-systems PE1 interfaces lt-1/2/0 unit 14 encapsulation ethernet set logical-systems PE1 interfaces lt-1/2/0 unit 14 peer-unit 13 set logical-systems PE1 interfaces lt-1/2/0 unit 14 family inet address 172.16.0.14/30 set logical-systems PE1 interfaces lo0 unit 3 family inet address 172.16.1.1/32 set logical-systems PE1 protocols ospf area 0.0.0.0 interface all set logical-systems PE1 protocols ospf area 0.0.0.0 interface fxp0.0 disable set logical-systems PE2 interfaces lt-1/2/0 unit 18 encapsulation ethernet set logical-systems PE2 interfaces lt-1/2/0 unit 18 peer-unit 17 set logical-systems PE2 interfaces lt-1/2/0 unit 18 family inet address 172.16.0.18/30 set logical-systems PE2 interfaces lo0 unit 4 family inet address 172.16.2.2/32 set logical-systems PE2 protocols ospf area 0.0.0.0 interface all set logical-systems PE2 protocols ospf area 0.0.0.0 interface fxp0.0 disable set logical-systems PE3 interfaces lt-1/2/0 unit 1 encapsulation ethernet set logical-systems PE3 interfaces lt-1/2/0 unit 1 peer-unit 2 set logical-systems PE3 interfaces lt-1/2/0 unit 1 family inet address 172.16.0.1/30 set logical-systems PE3 interfaces lo0 unit 1 family inet address 10.1.1.1/32 set logical-systems PE3 interfaces lo0 unit 1 family inet address 10.1.2.1/32 set logical-systems PE3 protocols ospf area 0.0.0.0 interface all set logical-systems PE3 protocols ospf area 0.0.0.0 interface fxp0.0 disable set logical-systems PE4 interfaces lt-1/2/0 unit 5 encapsulation ethernet set logical-systems PE4 interfaces lt-1/2/0 unit 5 peer-unit 6 set logical-systems PE4 interfaces lt-1/2/0 unit 5 family inet address 172.16.0.5/30 set logical-systems PE4 interfaces lo0 unit 2 family inet address 10.2.1.1/32 set logical-systems PE4 interfaces lo0 unit 2 family inet address 10.2.2.1/32 set logical-systems PE4 protocols ospf area 0.0.0.0 interface all set logical-systems PE4 protocols ospf area 0.0.0.0 interface fxp0.0 disable
在主路由器上配置防火墙过滤器
分步过程
下面的示例要求您在各个配置层级中进行导航。有关导航 CLI 的信息,请参阅 CLI 用户指南中的在配置模式下使用 CLI 编辑器。在配置模式下使用 CLI 编辑器https://www.juniper.net/documentation/en_US/junos/information-products/pathway-pages/junos-cli/junos-cli.html
要在主路由器上配置防火墙过滤器:
配置 SP1 客户的源地址。
[edit firewall filter classify-customers term sp1-customers] user@host# set from source-address 10.1.1.0/24 user@host# set from source-address 10.1.2.0/24
配置使用指定源地址接收数据包时执行的操作。
要跟踪防火墙过滤器的操作,请配置日志操作。逻辑系统 P1 上的 sp1-route-table.inet.0 路由表路由数据包。
[edit firewall filter classify-customers term sp1-customers] user@host# set then log user@host# set then logical-system P1 routing-instance sp1-route-table
配置 SP2 客户的源地址。
[edit firewall filter classify-customers term sp2-customers] user@host# set from source-address 10.2.1.0/24 user@host# set from source-address 10.2.2.0/24
配置使用指定源地址接收数据包时执行的操作。
要跟踪防火墙过滤器的操作,请配置日志操作。逻辑系统 P1 上的 sp2-route-table.inet.0 路由表路由数据包。
[edit firewall filter classify-customers term sp2-customers] user@host# set then log user@host# set then logical-system P1 routing-instance sp2-route-table
配置从任何其他源地址接收数据包时要执行的操作。
所有这些数据包都可以使用默认的 IPv4 单播路由表 inet.0 简单地接受和路由。
[edit firewall filter classify-customers term default] user@host# set then accept
在逻辑系统 P1 上配置路由实例
分步过程
下面的示例要求您在各个配置层级中进行导航。有关导航 CLI 的信息,请参阅 CLI 用户指南中的在配置模式下使用 CLI 编辑器。在配置模式下使用 CLI 编辑器https://www.juniper.net/documentation/en_US/junos/information-products/pathway-pages/junos-cli/junos-cli.html
要在逻辑系统上配置路由实例,请执行以下操作:
在逻辑系统上配置接口。
[edit logical-systems P1 interfaces lt-1/2/0] user@host# set unit 10 encapsulation ethernet user@host# set unit 10 peer-unit 9 user@host# set unit 10 family inet address 172.16.0.10/30 user@host# set unit 13 encapsulation ethernet user@host# set unit 13 peer-unit 14 user@host# set unit 13 family inet address 172.16.0.13/30 user@host# set unit 17 encapsulation ethernet user@host# set unit 17 peer-unit 18 user@host# set unit 17 family inet address 172.16.0.17/30
将 防火墙过滤器分配给路由器接口 lt-1/2/0.10 作为输入数据包过滤器。
classify-customers
[edit logical-systems P1 interfaces lt-1/2/0] user@host# set unit 10 family inet filter input classify-customers
使用路由协议或静态路由配置连接。
最佳做法是在管理接口上禁用路由。
[edit logical-systems P1 protocols ospf area 0.0.0.0] user@host# set interface all user@host# set interface fxp0.0 disable
创建路由实例。
这些路由实例在防火墙过滤器中 引用。
classify-customers
转发实例类型支持基于筛选条件的转发,其中接口不与实例关联。所有接口都属于默认实例,在本例中为逻辑系统 P1。
[edit logical-systems P1 routing-instances] user@host# set sp1-route-table instance-type forwarding user@host# set sp2-route-table instance-type forwarding
将路由实例中安装的路由解析为直接连接的下一跃点。
[edit logical-systems P1 routing-instances] user@host# set sp1-route-table routing-options static route 0.0.0.0/0 next-hop 172.16.0.13 user@host# set sp2-route-table routing-options static route 0.0.0.0/0 next-hop 172.16.0.17
将路由表组合在一起以形成路由表组。
第一个路由表 inet.0 是主路由表,其他路由表是辅助路由表。
主路由表确定路由表组(在本例中为 IPv4)的地址族。
[edit logical-systems P1 routing-options] user@host# set rib-groups fbf-group import-rib inet.0 user@host# set rib-groups fbf-group import-rib sp1-route-table.inet.0 user@host# set rib-groups fbf-group import-rib sp2-route-table.inet.0
将路由表组应用于 OSPF。
这会导致 OSPF 路由安装到组中的所有路由表中。
[edit logical-systems P1 protocols ospf] user@host# set rib-group fbf-group
如果完成设备配置,请提交配置。
[edit] user@host# commit
成果
通过发出 和 命令来确认您的配置。show firewall
show logical-systems P1
user@host# show firewall filter classify-customers { term sp1-customers { from { source-address { 10.1.1.0/24; 10.1.2.0/24; } } then { log; logical-system P1 routing-instance sp1-route-table; } } term sp2-customers { from { source-address { 10.2.1.0/24; 10.2.2.0/24; } } then { log; logical-system P1 routing-instance sp2-route-table; } } term default { then accept; } }
user@host# show logical-systems P1 interfaces { lt-1/2/0 { unit 10 { encapsulation ethernet; peer-unit 9; family inet { filter { input classify-customers; } address 172.16.0.10/30; } } unit 13 { encapsulation ethernet; peer-unit 14; family inet { address 172.16.0.13/30; } } unit 17 { encapsulation ethernet; peer-unit 18; family inet { address 172.16.0.17/30; } } } } protocols { ospf { rib-group fbf-group; area 0.0.0.0 { interface all; interface fxp0.0 { disable; } } } } routing-instances { sp1-route-table { instance-type forwarding; routing-options { static { route 0.0.0.0/0 next-hop 172.16.0.13; } } } sp2-route-table { instance-type forwarding; routing-options { static { route 0.0.0.0/0 next-hop 172.16.0.17; } } } } routing-options { rib-groups { fbf-group { import-rib [ inet.0 sp1-route-table.inet.0 sp2-route-table.inet.0 ]; } } }
验证
确认配置工作正常。
使用指定的源地址执行 ping 操作
目的
通过网络发送一些 ICMP 数据包以测试防火墙过滤器。
操作
登录到逻辑系统 PE3。
user@host> set cli logical-system PE3 Logical system: PE3
运行命令 ,对逻辑系统 PE1 上的 lo0.3 接口执行 ping 操作。
ping
此接口上配置的地址为 172.16.1.1。
指定源地址 10.1.2.1,即在逻辑系统 PE3 上的 lo0.1 接口上配置的地址。
user@host:PE3> ping 172.16.1.1 source 10.1.2.1 PING 172.16.1.1 (172.16.1.1): 56 data bytes 64 bytes from 172.16.1.1: icmp_seq=0 ttl=62 time=1.444 ms 64 bytes from 172.16.1.1: icmp_seq=1 ttl=62 time=2.094 ms ^C --- 172.16.1.1 ping statistics --- 2 packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max/stddev = 1.444/1.769/2.094/0.325 ms
登录到逻辑系统 PE4。
user@host:PE3> set cli logical-system PE4 Logical system: PE4
运行命令 ,对逻辑系统 PE2 上的 lo0.4 接口执行 ping 操作。
ping
此接口上配置的地址为 172.16.2.2。
指定源地址 10.2.1.1,即在逻辑系统 PE4 上的 lo0.2 接口上配置的地址。
user@host:PE4> ping 172.16.2.2 source 10.2.1.1 PING 172.16.2.2 (172.16.2.2): 56 data bytes 64 bytes from 172.16.2.2: icmp_seq=0 ttl=62 time=1.473 ms 64 bytes from 172.16.2.2: icmp_seq=1 ttl=62 time=1.407 ms ^C --- 172.16.2.2 ping statistics --- 2 packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max/stddev = 1.407/1.440/1.473/0.033 ms
意义
发送这些 ping 将激活防火墙过滤器操作。
验证防火墙过滤器
目的
确保防火墙过滤器操作生效。
操作
登录到逻辑系统 P1。
user@host> set cli logical-system P1 Logical system: P1
在逻辑系统 P1 上运行命令。
show firewall log
user@host:P1> show firewall log Log : Time Filter Action Interface Protocol Src Addr Dest Addr 13:52:20 pfe A lt-1/2/0.10 ICMP 10.2.1.1 172.16.2.2 13:52:19 pfe A lt-1/2/0.10 ICMP 10.2.1.1 172.16.2.2 13:51:53 pfe A lt-1/2/0.10 ICMP 10.1.2.1 172.16.1.1 13:51:52 pfe A lt-1/2/0.10 ICMP 10.1.2.1 172.16.1.1