僞裝網絡工程師14——路由選擇工具ip-prefix

1、背景介紹

ip-prefix做爲另外一種路由選擇工具經常使用在路由過濾的場景下,相較於技能過濾路由又能過濾數據包的acl,ip-prefix只能過濾路由條目,但他卻比acl在過濾路由時顆粒度更細,acl匹配的路由並不精確,由於一個完整的路由信息,包括網絡地址與掩碼,而acl只可以匹配路由的網絡地址,因此像1.1.1.0/24與1.1.1.0/25這兩個網段就沒法經過acl進行區分,此時就須要使用ip-prefix工具了 網絡

2、實驗拓撲

本次實驗拓撲以下圖所示:
僞裝網絡工程師14——路由選擇工具ip-prefix
路由器之間跑ospf協議,此時R2上經過ospf學到的路由爲 less

<R2>dis ip routing-table protocol ospf 
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : OSPF
         Destinations : 5        Routes : 5        

OSPF routing table status : <Active>
         Destinations : 5        Routes : 5

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

        1.1.1.0/24  OSPF    10   1           D   12.0.0.1        GigabitEthernet
0/0/0
        1.1.1.0/25  OSPF    10   1           D   23.0.0.3        GigabitEthernet
0/0/1
      1.1.1.128/25  OSPF    10   1           D   23.0.0.3        GigabitEthernet
0/0/1
        2.2.2.0/24  OSPF    10   1           D   12.0.0.1        GigabitEthernet
0/0/0
        2.2.2.0/25  OSPF    10   1           D   23.0.0.3        GigabitEthernet
0/0/1

OSPF routing table status : <Inactive>
         Destinations : 0        Routes : 0

若是此時只想讓R2學習到1.1.1.0/25跟1.1.1.128/25的網段地址,定義一個acl並引用 ide

[R2]acl 2000
[R2-acl-basic-2000]rule 10 permit source 1.1.1.0 0.0.0.128

[R2]ospf 1
[R2-ospf-1]filter-policy 2000 import

再看R2的路由表發現1.1.1.0/24也在R2的路由表中,印證了開頭的說明 工具

Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : OSPF
         Destinations : 3        Routes : 3        

OSPF routing table status : <Active>
         Destinations : 3        Routes : 3

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

        1.1.1.0/24  OSPF    10   1           D   12.0.0.1        GigabitEthernet
0/0/0
        1.1.1.0/25  OSPF    10   1           D   23.0.0.3        GigabitEthernet
0/0/1
      1.1.1.128/25  OSPF    10   1           D   23.0.0.3        GigabitEthernet
0/0/1

OSPF routing table status : <Inactive>
         Destinations : 0        Routes : 0

而用ip-prefix進行過濾,就能精確的抓取到路由 學習

[R2]ip ip-prefix A permit index 10 1.1.1.0 24 greater-equal 25 less-equal 25
[R2]ospf 1
[R2-ospf-1]filter-policy ip-prefix A import

相似於acl同樣,ip-prefix也須要被引用才能生效,且默認也包含deny全部未匹配到的路由,此時R2上的路由表爲 3d

[R2]display ip routing-table protocol ospf 
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : OSPF
         Destinations : 2        Routes : 2        

OSPF routing table status : <Active>
         Destinations : 2        Routes : 2

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

        1.1.1.0/25  OSPF    10   1           D   23.0.0.3        GigabitEthernet
0/0/1
      1.1.1.128/25  OSPF    10   1           D   23.0.0.3        GigabitEthernet
0/0/1

OSPF routing table status : <Inactive>
         Destinations : 0        Routes : 0

3、總結

根據實驗結果,能夠對ip-prefix工具作出如下總結: code

  1. ip-prefix只能過濾路由條目,且粒度更精確,與acl同樣使用通配符定義網段,後面使用greater-equal與less-equal精確掩碼位數
  2. 使用filter-policy調用時,只調用acl或ip-prefix其中一個
  3. 與acl同樣ip-prefix默認隱含一條deny全部未匹配的路由命令
  4. ip-prefix多用於路由過濾場景,且語句中的permit和denyacl中同樣表示爲選取和未選取
相關文章
相關標籤/搜索