示例:配置过滤器以根据前缀列表限制对端口的 TCP 访问
此示例说明如何配置标准无状态防火墙过滤器,通过指定包含允许的 BGP 对等方的前缀源列表,限制发往路由引擎的某些 TCP 和互联网控制消息协议 (ICMP) 流量。
要求
配置此示例之前,不需要除设备初始化之外的特殊配置。
概述
在此示例中,您将创建一个无状态防火墙过滤器,该过滤器阻止所有请求方对端口 179 的所有 TCP 连接尝试,但具有指定前缀的 BGP 对等方除外。
拓扑
将创建一个源前缀列表 ,用于指定包含允许的 BGP 对等方的源前缀列表。plist_bgp179
无状态防火墙过滤器 匹配源前缀列表中 与目标端口号 179 的所有数据包。filter_bgp179plist_bgp179
配置
CLI 快速配置
要快速配置此示例,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,更改与您的网络配置匹配所需的任何详细信息,然后将命令复制并粘贴到层次结构级别的 CLI 中。[edit]
set policy-options prefix-list plist_bgp179 apply-path "protocols bgp group <*> neighbor <*>" set firewall family inet filter filter_bgp179 term 1 from source-address 0.0.0.0/0 set firewall family inet filter filter_bgp179 term 1 from source-prefix-list plist_bgp179 except set firewall family inet filter filter_bgp179 term 1 from destination-port bgp set firewall family inet filter filter_bgp179 term 1 then reject set firewall family inet filter filter_bgp179 term 2 then accept set interfaces lo0 unit 0 family inet filter input filter_bgp179 set interfaces lo0 unit 0 family inet address 127.0.0.1/32
配置过滤器
分步过程
以下示例要求您在配置层次结构中导航各个级别。有关导航 CLI 的信息,请参阅《Junos OS CLI 用户指南》中的在配置模式下使用 CLI 编辑器。在配置模式下使用 CLI 编辑器https://www.juniper.net/documentation/en_US/junos/information-products/pathway-pages/junos-cli/junos-cli.html
要配置过滤器:
展开前缀列表 以包括由 定义的 BGP 对等组指向的所有前缀。bgp179protocols bgp group <*> neighbor <*>
[edit policy-options prefix-list plist_bgp179] user@host# set apply-path " protocols bgp group <*> neighbor <*>"
定义过滤器术语,该术语拒绝除指定 BGP 对等方之外的所有请求方对端口 179 的 TCP 连接尝试。
[edit firewall family inet filter filter_bgp179] user@host# set term term1 from source-address 0.0.0.0/0 user@host# set term term1 from source-prefix-list bgp179 except user@host# set term term1 from destination-port bgp user@host# set term term1 then reject
定义另一个过滤器术语以接受所有数据包。
[edit firewall family inet filter filter_bgp179] user@host# set term term2 then accept
将防火墙过滤器应用于环路接口。
[edit interfaces lo0 unit 0 family inet] user@host# set filter input filter_bgp179 user@host# set address 127.0.0.1/32
成果
在配置模式下,输入 、 和 命令确认您的配置。show firewallshow interfacesshow policy-options 如果输出未显示预期的配置,请重复此示例中的说明,以便进行更正。
user@host# show firewall family inet { filter filter_bgp179 { term 1 { from { source-address { 0.0.0.0/0; } source-prefix-list { plist_bgp179 except; } destination-port bgp; } then { reject; } } term 2 { then { accept; } } } }
user@host# show interfaces lo0 { unit 0 { family inet { filter { input filter_bgp179; } address 127.0.0.1/32; } } }
user@host# show policy-options prefix-list plist_bgp179 { apply-path "protocols bgp group <*> neighbor <*>"; }
如果完成设备配置,请从配置模式输入 commit。
验证
确认配置工作正常。
显示应用于环路接口的防火墙过滤器
目的
验证防火墙过滤器 是否已应用于逻辑接口 上的 IPv4 输入流量。filter_bgp179lo0.0
操作
对 逻辑接口 使用命令,并包括该 选项。show interfaces statistics operational mode
lo0.0detail 在 命令输出部分的部分下,该 字段显示应用于输入方向逻辑接口的无状态防火墙过滤器的名称。Protocol inetInput Filters
[edit] user@host> show interfaces statistics lo0.0 detail Logical interface lo0.0 (Index 321) (SNMP ifIndex 16) (Generation 130) Flags: SNMP-Traps Encapsulation: Unspecified Traffic statistics: Input bytes : 0 Output bytes : 0 Input packets: 0 Output packets: 0 Local statistics: Input bytes : 0 Output bytes : 0 Input packets: 0 Output packets: 0 Transit statistics: Input bytes : 0 0 bps Output bytes : 0 0 bps Input packets: 0 0 pps Output packets: 0 0 pps Protocol inet, MTU: Unlimited, Generation: 145, Route table: 0 Flags: Sendbcast-pkt-to-re Input Filters: filter_bgp179 Addresses, Flags: Primary Destination: Unspecified, Local: 127.0.0.1, Broadcast: Unspecified, Generation: 138