才子佳人博客

我的故事我讲述

juniper firewall filter的配置实例(实践篇)
 
来源:xjh  编辑:xjh  2015-03-24

环境:EX4200

文章给出juniper filter的配置实例,term是filter的基本构件块,from子句是匹配的条件,then子句是匹配后的动作行为,该实例分别从源地址和目标地址做限制,注意观察then 子句 accept,reject,discard三种不同的ping结果。

1.配置filter前用测试主机192.168.2.2 ping 101.7.152.1,有回复,如下:

C:UsersAdministrator.MYE2P1T6TPD1ANL>ping 101.7.152.1

正在 Ping 101.7.152.1 具有 32 字节的数据:
来自 101.7.152.1 的回复: 字节=32 时间<1ms TTL=63
来自 101.7.152.1 的回复: 字节=32 时间<1ms TTL=63
来自 101.7.152.1 的回复: 字节=32 时间<1ms TTL=63
来自 101.7.152.1 的回复: 字节=32 时间<1ms TTL=63

101.7.152.1 的 Ping 统计信息:

数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):

最短 = 0ms,最长 = 0ms,平均 = 0ms

2.配置filter
root@ex4200# top

{master:0}[edit]
root@ex4200# edit firewall

{master:0}[edit firewall]
root@ex4200# show
/*
拒绝来自192.168.2.0/24网段的数据包,其它网段数据包则接收
*/
family inet {

filter filter-in-test {

term block-packets {

from {

source-address {

192.168.2.0/24;

}

}

then reject;

}

term accept-others {

then accept;

}

}
/*
仅仅接收去往192.168.50.2/32主机的数据包,其它数据包一概丢弃
*/

filter web-server {

term allow-web {

from {

destination-address {

192.168.50.2/32;

}

protocol tcp;

}

then accept;

}

term deny-other-web {

from {

protocol tcp;

}

then {

discard;

}

}

}
}


{master:0}[edit firewall]
root@ex4200# show |display set
set firewall family inet filter filter-in-test term block-packets from source-address 192.168.2.0/24
set firewall family inet filter filter-in-test term block-packets then reject
set firewall family inet filter filter-in-test term accept-others then accept

set firewall family inet filter web-server term allow-web from destination-address 192.168.50.2/32
set firewall family inet filter web-server term allow-web from protocol tcp
set firewall family inet filter web-server term allow-web then accept
set firewall family inet filter web-server term deny-other-web from protocol tcp
set firewall family inet filter web-server term deny-other-web then discard

{master:0}[edit firewall]
root@ex4200#

3.在interfaces ge-0/0/3 上 配置 input filter filter-in-test

{master:0}[edit interfaces ge-0/0/3 unit 0 family inet]
root@ex4200# set filter input filter-in-test

....
{master:0}[edit interfaces ge-0/0/3]
root@ex4200# show
unit 0 {

family inet {

filter {

input filter-in-test;

}

address 101.7.152.1/24;

}
}


在interfaces ge-0/0/18 配置filter input web-server
{master:0}[edit interfaces ge-0/0/18]
root@ex4200# show
unit 0 {

family inet {

filter {

input web-server;

}

address 101.7.156.1/24;

}
}

{master:0}[edit interfaces ge-0/0/18]
root@ex4200#

4.配置filter后,用测试主机192.168.2.2 ping 101.7.152.1,则得到来自 101.7.152.1 的回复: 无法访问目标网,数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失)。

C:UsersAdministrator.MYE2P1T6TPD1ANL>ping 101.7.152.1

正在 Ping 101.7.152.1 具有 32 字节的数据:
来自 101.7.152.1 的回复: 无法访问目标网。
来自 101.7.152.1 的回复: 无法访问目标网。
来自 101.7.152.1 的回复: 无法访问目标网。
来自 101.7.152.1 的回复: 无法访问目标网。

101.7.152.1 的 Ping 统计信息:

数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),


5.配置filter后,用测试主机192.168.2.2 ping 101.7.152.1 ,回复无法访问目标网,但来自指定路由实例的ping则可以
{master:0}[edit interfaces ge-0/0/3]
root@ex4200# run ping 101.7.152.1 routing-instance new_instance4
PING 101.7.152.1 (101.7.152.1): 56 data bytes
64 bytes from 101.7.152.1: icmp_seq=0 ttl=64 time=1.332 ms
64 bytes from 101.7.152.1: icmp_seq=1 ttl=64 time=1.151 ms
64 bytes from 101.7.152.1: icmp_seq=2 ttl=64 time=1.144 ms
64 bytes from 101.7.152.1: icmp_seq=3 ttl=64 time=1.158 ms
64 bytes from 101.7.152.1: icmp_seq=4 ttl=64 time=1.328 ms
64 bytes from 101.7.152.1: icmp_seq=5 ttl=64 time=1.149 ms
64 bytes from 101.7.152.1: icmp_seq=6 ttl=64 time=1.157 ms
64 bytes from 101.7.152.1: icmp_seq=7 ttl=64 time=1.147 ms
64 bytes from 101.7.152.1: icmp_seq=8 ttl=64 time=1.340 ms
64 bytes from 101.7.152.1: icmp_seq=9 ttl=64 time=2.162 ms
64 ^C
--- 101.7.152.1 ping statistics ---
11 packets transmitted, 11 packets received, 0% packet loss
round-trip min/avg/max/stddev = 1.144/1.293/2.162/0.286 ms

6.更改filter filter-in-test then 子句为discard,再用测试主机192.168.2.2 ping,则无法得到来自 101.7.152.1 的回复,给出提示为请求超时,接收0个包,丢失100%

{master:0}[edit firewall]
root@ex4200# show
family inet {

filter filter-in-test {

term block-packets {

from {

source-address {

192.168.2.0/24;

}

}

then {

discard;

}

}

term accept-others {

then accept;

}

}
}



关键知识点补充说明:

term是filter的基本构件块,from子句是匹配的条件,then子句是匹配后的动作行为,一个filter至少包含一个term。

一个策略中可以包含多个term,一个term中可包含多个匹配条件或多个动作,路由器按顺序评估这些term,term的顺序至关重要,影响匹配结果。

在from子句中,一个匹配条件里的多个参数间是逻辑或(因此同一匹配条件里的各种参数至少要有一个被匹配才能认为被匹配),不同条件间是逻辑与,看如下示例即明白所叙。

term allow-web {

from

{

destination-address {

192.168.50.2/32;

192.168.50.3/32;

192.168.50.4/32;

}

protocol tcp;

port 80;

}

then accept;
}

与CISCO一样,策略中有默认缺省动作:丢弃,即没有明确允许的话则一概丢弃处理。term子句中若无from子句,则暗示匹配条件任意,若无then子句则默认为accept。

term的顺序至关重要,可以在策略配置层次下使用insert命令调整各个term的顺序。一个term被匹配并执行后,如果执行动作不是next term,而是终结动作determinating action,如accept,reject,discard,则路由器停止策略评估,不再继续。其中accept动作放行数据包,reject动作丢弃数据包,并给源地址一个返回包。discard动作直接丢弃数据包,不给回应讯息。

策略链:一个策略链中包含多个策略,每个策略都被集中放置在policy-option中,这些策略的顺序取决于应用时你组织的策略链,而不是在policy-option中的顺序。

策略链中,当被执行了一个终结动作时(接受、拒绝、丢弃等)策略链即中止。在策略链中最后还存在一个缺省策略:丢弃。


分类:网络日志| 查看评论
相关文章
文章点击排行
本年度文章点击排行
发表评论:
  • 昵称: *
  • 邮箱: *
  • 网址:
  • 评论:(最多100字)
  • 验证码: