天天看點

政策路由PBR詳解

前言:set ip next-hop後面跟多個IP啥意思?recursive next-hop是什麼?next-hop如果挂了咋辦?有沒有辦法檢測可達性?PBR在實際工程環境中如何應用?請浏覽本文:

一、指令彙總

1.set ip next-hop  {  ip-address  [...ip-address]  |  recursive  ip-address  }

允許寫多個下一跳IP,但這些IP必須是直連路由器的接口IP

如果定義了多個下一跳IP,則當第一個下一跳關聯的本地出接口DOWN掉,則自動切換到下一個next-hop

recursive next-hop(遞歸下一跳)特性突破了傳統下一跳必須是直連路由器下一跳接口IP的限制。Recursive next-hop可以不是直連網絡,隻要路由表中有相關的路由可達即可。一般recursive next-hop不可達,資料将交由路由處理(一般就被預設路由比對走了)

如果在一個route-map清單的同一個序列中同時使用ip next-hop及ip next-hop recursive,則ip next-hop 有效。如果ip next-hop 挂了,則啟用ip next-hop recursive,如果ip next-hop recursive和ip next-hop 都挂了,則丢給路由表處理。注意:一個route-map序列,隻允許配置一個ip next-hop recursive

2. set ip next-hop verify-availability  [ next-hop-address  sequence  track object ]

檢測下一跳的可達性,預設是關閉的

Sequence of next hops. The acceptable range is from 1 to 65535.

此條指令可以下列方式使用:

  • 在PBR環境下使用CDP檢測下一跳IP可達性(不加後面的可選參數)

使用該特性可能會一定程度上降低裝置性能,另外必須保證自己以及鄰居路由器接口CDP都是開啟的,最後過程交換及CEF都支援該特性,但dCEF不支援。

該特性借助裝置的CDP表來判斷下一跳的可達性,

如果本端開啟了該特性,next-hop裝置不支援CDP,則切換至下一個next-hop,如果沒,則跳過PBR

如果本端沒開啟該特性,那麼資料包要麼被成功政策路由,要麼永遠無法正常路由出去(被丢棄)

如果僅僅想檢測部分next-hop裝置的可達性,則可以配置不同的route-map條目,來選擇性的使用該特性(同一個route-map)。

  • 結合object tracking來檢測一個遠端裝置(或IP)的可達性

使用object tracking,PBR可以做的更加靈活,可依據ICMP、HTTP、路由表中某條路由的存在與否、接口的up/DOWN等來進行決策。

注意: 如若基于CDP的檢測及基于object tracking的檢測都應用了,則後者優先

3. set ip next-hop 與set ip default next-hop的差別比較簡單,這裡就不解析了

二 實驗驗證

2.1 set ip next-hop

​​

政策路由PBR詳解

​​

GW的配置如下:

access-list 1 permit any

route-map PBR permit 10

match ip address 1

set ip next-hop 10.1.1.2 10.2.2.2

interface fast 1/0

!! GW并無其他關于路由的配置

實驗現象:

1.當網絡正常時,資料強制走ISP1,ping 100的遠端網絡資料到ISP1

2.當ISP1當機時,GW連接配接ISP1的接口DOWN掉,則PC通路100的流量自動切換至ISP2

3.當ISP1當機時,且GW檢測不到時(也就是GW連接配接ISP1的接口沒DOWN),PC通路100的流量仍然被扔給ISP1,這就斷網了

補充:

Set ip next-hop ip1 ip2 ip3,這個知識點已經沒問題了吧?match住相關條件後,資料包首先被送到第一個next-hop ip address,如果這個ip位址所關聯的直連接配接口DOWN了,則切換至下一個next-hop ip address,如此反複,可以配置多個next-hop。但是,如果直連的next-hop(對端路由器或其接口)自己挂了,而本地直連接配接口沒感覺到(如中間串了台switch),則無法自動切換,路由器仍然會一股腦的把資料丢給這個next-hop。

另外,如果配置的時候指令這麼寫的話:

Set ip next-hop ip1

Set ip next-hop ip2

……

則IOS會自動将指令變成Set ip next-hop ip1 ip2 ……

2.2 set ip next-hop verify-availability

​​

政策路由PBR詳解

​​

GW的配置如下:

access-list 1 permit any

route-map PBR permit 10

match ip address 1

set ip next-hop 10.1.1.2 10.2.2.2

set ip next-hop verify-availability

interface fast 1/0

!! GW并無其他關于路由的配置

!! ISP1、ISP2及GW都需開啟CDP

實驗現象:

1.當網絡正常時,資料強制走ISP1,ping 100的遠端網絡資料到ISP1

2.當ISP1當機時,且GW連接配接ISP1的接口DOWN掉,則PC通路100網絡的資料切換至ISP2

3.當ISP1當機時,且GW連接配接ISP1的接口沒DOWN(如關閉ISP1的CDP),由于GW丢失了ISP1的CDP資訊,是以仍未ISP1挂了,于是PC通路100網絡的資料切換至ISP2,網絡不斷

2.3 set ip next-hop verify-availability基于object tracking

​​

政策路由PBR詳解

​​

GW的配置如下:

ip sla monitor responder

ip sla monitor 1

type echo protocol ipIcmpEcho 10.1.1.2 source-ipaddr 10.1.1.1

frequency 10

exit

ip sla monitor schedule 1 life forever start-time now

track 1 rtr 1 reachability

ip sla monitor 2

type echo protocol ipIcmpEcho 10.2.2.2 source-ipaddr 10.2.2.1

frequency 10

exit

ip sla monitor schedule 2 life forever start-time now

track 2 rtr 2 reachability

access-list 1 permit any

route-map PBR permit 10

match ip address 1

set ip next-hop verify-availability 10.1.1.2 10 track 1

set ip next-hop verify-availability 10.2.2.2 20 track 2

實驗現象:

1.當網絡正常時,資料強制走ISP1,ping 100的遠端網絡資料到ISP1

2.當ISP1故障,GW通過tracking感覺到,于是資料切換至ISP2

3.回複ISP1,GW通過tracking感覺到,資料又切換回ISP1

技術解析:

1. 首先定義track object,關聯到一個ip sla monitor

使用ICMP協定去探測10.1.1.2的可達性(使用源位址10.1.1.1去ping10.1.1.2)

Track object 的ID為1,關聯到ip sla monitor 1

當10.1.1.2可達,則track 對象為true

ip sla monitor 1

type echo protocol ipIcmpEcho 10.1.1.2 source-ipaddr 10.1.1.1

frequency 10

exit

ip sla monitor schedule 1 life forever start-time now

track 1 rtr 1 reachability

2. 然後在route-map中調用該track object

route-map PBR permit 10

match ip address 1

set ip next-hop verify-availability 10.1.1.2 10 track 1

當track1為true,也就是10.1.1.2可達,則PC通路100網絡的資料被丢給10.1.1.2,如果track 1挂了,則切換至下一個next-hop

2.4 set ip next-hop recursive

​​

政策路由PBR詳解

​​

GW的配置如下:

access-list 1 permit any

route-map PBR permit 10

match ip address 1

set ip next-hop 10.2.2.2

set ip next-hop recursive 10.1.12.2

ip route 10.1.12.0 255.255.255.0 10.1.1.2

ip route 0.0.0.0 0.0.0.0 serial s0/2

實驗現象:

1.正常情況下,資料優先走ip next-hop,也就是走ISP2

2.當GW連接配接ISP2的出接口DOWN掉(也就是ISP2挂了),則切換至ip next-hop recursive,也就是ISP2

注意,這個時候是才用路由表遞歸找到去往10.1.12.2的路由的,是以路由表裡必須有可達路由 

3.當GW丢失了去往10.1.12.2的路由,并且連接配接ISP2的連接配接也丢失了,則走預設路由