天天看點

IP prefix-list、ACL、route-map的比較

【文法】:

<b>ip prefix-list </b>list-name [<b>seq</b> seq-value] {<b>deny|permit}</b> network/len [<b>ge</b> ge-value] [<b>le</b> le-value]

ge,大于等于

le,小于等于

如果隻出現ge,範圍從 ge-value --&gt; 32

如果隻出現le,範圍從length--&gt;le-value

【分析】

字首清單中的ge ,le 的了解

假定有三條路由

172.16.0.0/16

172.16.10.0/24

172.16.11.0/24

 <b>設定比對條件</b>

<b> 比對結果</b>

ip prefix-list permit 172.16.10.0/8 le 24

 ip prefix-list permit 172.16.10.0/8 le 16

 in prefix-list tenonly permit 172.16.10.0/8 ge 16 le 24

172.16.0.0/16 

 in prefix-list tenonly permit 172.16.10.0/8 ge 17 le 24

 172.16.10.0/24

其實ACL也有方法定義一個範圍,以實作類似prefix-list的功能。 

access-list 10 permit 199.172.0.0 0.0.3.0,這裡這個0.0.3.0,即起了一個定義範圍的作用,0表示match,1表示不關心。這樣的話,199.172.0.0 這個被定義物裡,前16個bit和最後8個bit都是被定死的,唯獨第三段的最後2bit是不關心的,可以變換,是以結果就是:

199.172.0.0

199.172.1.0 

199.172.2.0

199.172.3.0

per 199.172.1.0 0.0.254.0   奇數路由

per 199.172.0.0 0.0.254.0   偶數路由

在進行路由過濾和位址限制方面,Prefix-list占用CPU的資源比采用access-list要少很多, 

它提供更快的通路清單裝入速度,目前IOS版本11.1CC(17),11.3(3)和12.0都提供該項特性。 

Prefix-list儲存了access-list的多項重要特性: 

1、Permit和Deny; 

2、最先比對法則; 

3、基于Prefix長度的過濾(精确比對或range比對) 

Prefix-list與ACL的不同之處:

Prefix-list可以采用增量方式從新定義,也就是說,它裡面的條目可以單獨增加或删除,而無需像access-list一樣,一删就得将整個access-list删掉重寫。

ACL , prefix , route-map共同特點:

 一個空的/不存在 的acl &amp; prefix預設是permit all ,一個不存在 的 route-map 預設是deny all 

 一個acl 如果配置一條以上permit或deny語句,最後一筆為隐藏的deny all

 route-map預設deny all(即使為空) 

----------------------------------------------------------------------- 

以下為各種例子,以如下的網絡架構為網絡環境:

R1 (s1/0,192.168.1.1) ===============   (s1/0,192.168.1.2) R2

Case Study: ACL

R1#conf t

R1(config)#line vty 0 4

R1(config-line)#password cisco

R1(config-line)#login

R1(config-line)#access-class 3 in

R2#telnet 192.168.1.1 

Password :

R1&gt;   沒有阻擋可以直接進去

Summary: 空的(未定義的)acl預設允許所有的主機。

-----------------------------------------------------------------------

Case Study: Route-map

R1(config)#router ospf 100

R1(config-router)#default-information originate route-map sense

R1(config-router)#exit

R2#sh ip route

Gateway of last resort is not set

    172.16.0.0/24 is subnetted, 2 subnets

O    172.16.1.0 [110/65] via 192.168.1.1, 00:32:38, Serial1/0

C    172.16.2.0 is directly connected, Loopback0

    192.168.1.0/30 is subnetted, 1 subnets

C    192.168.1.0 is directly connected, Serial1/0

注: 不存在的route-map預設deny all。是以這個case的route-map永遠傳回不滿足要求。

R1(config)#route-map sense permit 10

Gateway of last resort is 192.168.1.6 to network 0.0.0.0

O*E2 0.0.0.0/0 [110/1] via 192.168.1.6, 00:00:12, Serial1/1

R1(config-route-map)#match ip add 1

R1(config)#route-map sense deny 10

Case Study: Prefix-list

R1(config)#int lo0

R1(config-if)#ip add 172.16.33.1 255.255.255.0

R1(config-if)#no shut

R1(config-if)#ip ospf network point-to-point

R1(config-if)#exit

R1(config-router)#redistribute connected subnets

R1(config-router)#distribute-list prefix sense out connected

R1(config)#

    172.16.0.0/24 is subnetted, 4 subnets

O    172.16.44.0 [33/65] via 192.168.1.1, 00:07:54, Serial1/0

O E2 172.16.33.0 [55/20] via 192.168.1.1, 00:00:01, Serial1/0

O IA 172.16.1.0 [44/65] via 192.168.1.1, 00:07:54, Serial1/0

R1(config)#ip prefix-list sense seq 5 deny 172.16.33.0/24 

rtb#sh ip route

    172.16.0.0/24 is subnetted, 3 subnets

O    172.16.44.0 [33/65] via 192.168.1.1, 00:09:15, Serial1/0

O IA 172.16.1.0 [44/65] via 192.168.1.1, 00:09:15, Serial1/0

Summary: 空的prefix-list預設允許所有的路由。

Case Study: Integrate Route-map and ACL

R1(config)#route-map sense deny 5

R1(config-route-map)#match ip address 33

R1(config-route-map)#

R2#sh ip route 

總結: 至少定義一條permit或deny語句才能使用acl或route-map的隐含deny功能。空的acl預設允所有的路由。

本文轉自zcm8483 51CTO部落格,原文連結:http://blog.51cto.com/haolun/993172

繼續閱讀