示例:配置过滤器以阻止对端口的 TCP 访问(来自指定 BGP 对等方除外)
此示例说明如何配置标准无状态防火墙过滤器,以阻止除指定 BGP 对等方之外的所有请求方对端口 179 的所有 TCP 连接尝试。
要求
在配置此示例之前,不需要除设备初始化之外的特殊配置。
概述
在此示例中,您将创建一个无状态防火墙过滤器,用于阻止除指定 BGP 对等方之外的所有请求者对端口 179 的所有 TCP 连接尝试。
无状态防火墙过滤器 会将来自设备 A 和设备 B 上直接连接的接口的所有数据包与目标端口号 179 进行匹配。filter_bgp179
配置
CLI 快速配置
要快速配置此示例,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,更改与您的网络配置匹配所需的任何详细信息,然后将命令复制并粘贴到层次结构级别的 CLI 中。[edit]
设备 C
set interfaces ge-1/2/0 unit 10 description to-E set interfaces ge-1/2/0 unit 10 family inet address 10.10.10.10/30 set protocols bgp group external-peers type external set protocols bgp group external-peers peer-as 17 set protocols bgp group external-peers neighbor 10.10.10.9 set routing-options autonomous-system 22
设备 E
set interfaces ge-1/2/0 unit 0 description to-A set interfaces ge-1/2/0 unit 0 family inet address 10.10.10.1/30 set interfaces ge-1/2/1 unit 5 description to-B set interfaces ge-1/2/1 unit 5 family inet address 10.10.10.5/30 set interfaces ge-1/0/0 unit 9 description to-C set interfaces ge-1/0/0 unit 9 family inet address 10.10.10.9/30 set interfaces lo0 unit 2 family inet filter input filter_bgp179 set interfaces lo0 unit 2 family inet address 192.168.0.1/32 set protocols bgp group external-peers type external set protocols bgp group external-peers peer-as 22 set protocols bgp group external-peers neighbor 10.10.10.2 set protocols bgp group external-peers neighbor 10.10.10.6 set protocols bgp group external-peers neighbor 10.10.10.10 set routing-options autonomous-system 17 set firewall family inet filter filter_bgp179 term 1 from source-address 10.10.10.2/32 set firewall family inet filter filter_bgp179 term 1 from source-address 10.10.10.6/32 set firewall family inet filter filter_bgp179 term 1 from destination-port bgp set firewall family inet filter filter_bgp179 term 1 then accept set firewall family inet filter filter_bgp179 term 2 then reject
配置设备 E
分步过程
以下示例要求您在配置层次结构中导航各个级别。有关导航 CLI 的信息,请参阅《Junos OS CLI 用户指南》中的在配置模式下使用 CLI 编辑器。在配置模式下使用 CLI 编辑器https://www.juniper.net/documentation/en_US/junos/information-products/pathway-pages/junos-cli/junos-cli.html
要使用无状态防火墙过滤器配置设备 E,以阻止除指定 BGP 对等方之外的所有请求者对端口 179 的所有 TCP 连接尝试,请执行以下操作:
配置接口。
user@E# set interfaces ge-1/2/0 unit 0 description to-A user@E# set interfaces ge-1/2/0 unit 0 family inet address 10.10.10.1/30 user@E# set interfaces ge-1/2/1 unit 5 description to-B user@E# set interfaces ge-1/2/1 unit 5 family inet address 10.10.10.5/30 user@E# set interfaces ge-1/0/0 unit 9 description to-C user@E# set interfaces ge-1/0/0 unit 9 family inet address 10.10.10.9/30
配置 BGP。
[edit protocols bgp group external-peers] user@E# set type external user@E# set peer-as 22 user@E# set neighbor 10.10.10.2 user@E# set neighbor 10.10.10.6 user@E# set neighbor 10.10.10.10
配置自治系统编号。
[edit routing-options] user@E# set autonomous-system 17
定义接受来自指定 BGP 对等方的端口 179 的 TCP 连接尝试的过滤器术语。
[edit firewall family inet filter filter_bgp179] user@E# set term 1 from source-address 10.10.10.2/32 user@E# set term 1 from source-address 10.10.10.6/32 user@E# set term 1 from destination-port bgp user@E# set term 1 then accept
定义其他过滤器术语以拒绝来自其他源的数据包。
[edit firewall family inet filter filter_bgp179] user@E# set term 2 then reject
将防火墙过滤器应用于环路接口。
[edit interfaces lo0 unit 2 family inet] user@E# set filter input filter_bgp179 user@E# set address 192.168.0.1/32
成果
在配置模式下,输入 show firewall 、show interfaces、show protocols 和 show routing-options 命令,以确认您的配置。如果输出未显示预期的配置,请重复此示例中的说明,以便进行更正。
user@E# show firewall family inet { filter filter_bgp179 { term 1 { from { source-address { 10.10.10.2/32; 10.10.10.6/32; } destination-port bgp; } then accept; } term 2 { then { reject; } } } }
user@E# show interfaces lo0 { unit 2 { family inet { filter { input filter_bgp179; } address 192.168.0.1/32; } } } ge-1/2/0 { unit 0 { description to-A; family inet { address 10.10.10.1/30; } } } ge-1/2/1 { unit 5 { description to-B; family inet { address 10.10.10.5/30; } } } ge-1/0/0 { unit 9 { description to-C; family inet { address 10.10.10.9/30; } } }
user@E# show protocols bgp { group external-peers { type external; peer-as 22; neighbor 10.10.10.2; neighbor 10.10.10.6; neighbor 10.10.10.10; } }
user@E# show routing-options autonomous-system 17;
如果完成设备配置,请从配置模式输入 commit。
验证
确认配置工作正常。
验证是否已配置过滤器
目的
确保筛选器列在命令的 输出中。show firewall filter
操作
user@E> show firewall filter filter_bgp179 Filter: filter_bgp179
验证 TCP 连接
目的
验证 TCP 连接。
操作
在操作模式下, 在设备 C 和设备 E 上运行命令。show system connections extensive
设备 C 上的输出显示了建立 TCP 连接的尝试。设备 E 上的输出显示仅与设备 A 和设备 B 建立连接。
user@C> show system connections extensive | match 10.10.10 tcp4 0 0 10.10.10.9.51872 10.10.10.10.179 SYN_SENT
user@E> show system connections extensive | match 10.10.10 tcp4 0 0 10.10.10.5.179 10.10.10.6.62096 ESTABLISHED tcp4 0 0 10.10.10.6.62096 10.10.10.5.179 ESTABLISHED tcp4 0 0 10.10.10.1.179 10.10.10.2.61506 ESTABLISHED tcp4 0 0 10.10.10.2.61506 10.10.10.1.179 ESTABLISHED
监控接口上的流量
目的
使用命令将 建立 TCP 连接的接口上的流量与未建立 TCP 连接的接口上的流量进行比较。monitor traffic
操作
在操作模式下, 在设备 B 的设备 E 接口和设备 C 的设备 E 接口上运行命令。以下示例输出验证在第一个示例中是否收到了确认 () 消息。monitor trafficack 在第二个示例中, 未收到消息。ack
user@E> monitor traffic size 1500 interface ge-1/2/1.5 19:02:49.700912 Out IP 10.10.10.5.bgp > 10.10.10.6.62096: P 3330573561:3330573580(19) ack 915601686 win 16384 <nop,nop,timestamp 1869518816 1869504850>: BGP, length: 19 19:02:49.801244 In IP 10.10.10.6.62096 > 10.10.10.5.bgp: . ack 19 win 16384 <nop,nop,timestamp 1869518916 1869518816> 19:03:03.323018 In IP 10.10.10.6.62096 > 10.10.10.5.bgp: P 1:20(19) ack 19 win 16384 <nop,nop,timestamp 1869532439 1869518816>: BGP, length: 19 19:03:03.422418 Out IP 10.10.10.5.bgp > 10.10.10.6.62096: . ack 20 win 16384 <nop,nop,timestamp 1869532539 1869532439> 19:03:17.220162 Out IP 10.10.10.5.bgp > 10.10.10.6.62096: P 19:38(19) ack 20 win 16384 <nop,nop,timestamp 1869546338 1869532439>: BGP, length: 19 19:03:17.320501 In IP 10.10.10.6.62096 > 10.10.10.5.bgp: . ack 38 win 16384 <nop,nop,timestamp 1869546438 1869546338>
user@E> monitor traffic size 1500 interface ge-1/0/0.9 18:54:20.175471 Out IP 10.10.10.9.61335 > 10.10.10.10.bgp: S 573929123:573929123(0) win 16384 <mss 1460,nop,wscale 0,nop,nop,timestamp 1869009240 0,sackOK,eol> 18:54:23.174422 Out IP 10.10.10.9.61335 > 10.10.10.10.bgp: S 573929123:573929123(0) win 16384 <mss 1460,nop,wscale 0,nop,nop,timestamp 1869012240 0,sackOK,eol> 18:54:26.374118 Out IP 10.10.10.9.61335 > 10.10.10.10.bgp: S 573929123:573929123(0) win 16384 <mss 1460,nop,wscale 0,nop,nop,timestamp 1869015440 0,sackOK,eol> 18:54:29.573799 Out IP 10.10.10.9.61335 > 10.10.10.10.bgp: S 573929123:573929123(0) win 16384 <mss 1460,sackOK,eol> 18:54:32.773493 Out IP 10.10.10.9.61335 > 10.10.10.10.bgp: S 573929123:573929123(0) win 16384 <mss 1460,sackOK,eol> 18:54:35.973185 Out IP 10.10.10.9.61335 > 10.10.10.10.bgp: S 573929123:573929123(0) win 16384 <mss 1460,sackOK,eol>