淺析PBR(基于策略的路由)
PBR(基于策略的路由)概述
基于策略的路由(PBR)是一種靈活的數據包路由轉發機制。通過在路由器上應用策略路由,使路由器根據路由映射(route-map)決定經過路由器的數據包如何處理。路由映射決定了一個數據包的下一跳轉發路由器。
在路由器上應用策略路由,必須要指定策略路由使用的路由映射(route-map),并且要創建路由映射。一個路由映射由很多條策略組成,每個策略都定義了1個或多個匹配規則和對應操作。一個接口應用策略路由后,將對該接口收到的所有包進行檢查,不符合路由映射中所定義的數據包將會被按照正常路由轉發進行處理,符合路由映射中的策略的數據包,就按照策略中定義的操作進行處理。
策略路由主要應用在企業路由表復雜或者需要對路由進行控制的情況下,特別是當企業網絡出口有兩條,需要對不同服務和應用或者不同客戶端的路由進行控制時,當然企業內部運行兩個網絡或者更多的網絡時也經常要用到路由策略;另外,策略路由除了應用在非正常的路由選路之外,它還可以用來防止病毒或黑客的攻擊,使用條件語句將病毒或攻擊的特征碼匹配出來,然后再指定一個安全策略(如使用黑洞路由)將攻擊阻斷.
黑洞路由是對動態路由選擇協議的一個補充。黑洞路由可以將不想要的流量轉發到一個稱為null0的接口中去。我們可以建立一條或一些靜態路由,將精確匹配這些路由的流量丟棄。和ACL不同的是,Cisco IOS的所有交換過程,包括CEF,都能處理黑洞路由,而不降低性能。需要注意的是,PBR技術不支持配置了PBR的路由器始發流量和到達該路由器的流量。
PBR(基于策略的路由)實例解析
下面我們就以一個試驗來描述策略路由的阻斷流量的功能。路由器的E0/0口作為內部網絡的網關,地址為200.1.1.1,內部網絡有一個WWW服務器,地址為200.1.1.100,和WWW同一網段內有普通用戶PC一臺,在外部網絡有一個遠程的用戶,IP地址為199.1.1.100,允許遠程用戶能夠訪問WWW服務器,同時不允許訪問內部用戶的PC機,使用PBR完成需求。
在路由器上配置相關的地址,并測試與200.1.1.100,200.1.1.10和199.1.1.100的連通性。配置一個路由映射(route-map),匹配從遠程用戶到內部用戶的流量,并牽引到null0接口中去,并在null0接口下配置不返回不可達信息。其他不匹配路由映射的流量正常轉發。
#p#
路由器的初始配置如下:
- Router(config)#interface Ethernet0/0
- Router(config-if)#ip address 200.1.1.1 255.255.255.0
- Router(config-if)#exit
- Router(config)#interface Ethernet0/1
- Router(config-if)#ip address 199.1.1.1 255.255.255.0
- Router(config-if)#exit
測試連通性:
- Router#ping 200.1.1.100
- Type escape sequence to abort.
- Sending 5, 100-byte ICMP Echos to 200.1.1.100, timeout is 2 seconds:
- !!!!!
- Success rate is 100 percent (5/5), round-trip min/avg/max = 1/3/4 ms
- Router #ping 200.1.1.10
- Type escape sequence to abort.
- Sending 5, 100-byte ICMP Echos to 200.1.1.10, timeout is 2 seconds:
- !!!!!
- Success rate is 100 percent (5/5), round-trip min/avg/max = 1/2/4 ms
- Router #ping 199.1.1.100
- Type escape sequence to abort.
- Sending 5, 100-byte ICMP Echos to 199.1.1.100, timeout is 2 seconds:
- !!!!!
- Success rate is 100 percent (5/5), round-trip min/avg/max = 1/3/4 ms
配置匹配敏感流量的ACL:
- Router(config)#access-list 100 permit ip host 199.1.1.1 host 200.1.1.10
配置null0接口:
- Router(config)#interface null 0
- Router(config-if)#no ip unreachables
建立路由映射:
- Router(config)#route-map pbr
- Router(config- route-map)#match ip address 100
- Router(config- route-map)#set interface null 0
在出口路由器的E0/1接口上打開NETFLOW交換功能,方便我們對結果進行查看,并在該接口上調用PBR:
- Router(config)#interface Ethernet0/1
- Router(config-if)#ip route-cache flow
- Router(config-if)# ip policy route-map pbr
- Router(config-if)#exit
- 在遠程主機上對內網的設備再次進行連通性測試:
- C:\>ping 200.1.1.100
- Pinging 200.1.1.100 with 32 bytes of data:
- Reply from 200.1.1.100: bytes=32 time<1ms TTL=128
- Reply from 200.1.1.100: bytes=32 time<1ms TTL=128
- Reply from 200.1.1.100: bytes=32 time<1ms TTL=128
- Reply from 200.1.1.100: bytes=32 time<1ms TTL=128
- Ping statistics for 200.1.1.100:
- Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
- Approximate round trip times in milli-seconds:
- Minimum = 0ms, Maximum = 0ms, Average = 0ms
- C:\>ping 200.1.1.10
- Pinging 200.1.1.10 with 32 bytes of data:
- Request timed out.
- Request timed out.
- Request timed out.
- Request timed out.
- Ping statistics for 200.1.1.10:
- Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),
這時,會發現外部網絡的遠程用戶已經無法ping通內部的用戶了,但是還是可以ping通WWW服務器。查看邊界路由器的狀態:
- Router#show access-lists
- Extended IP access list 100
- 10 permit ip host 199.1.1.100 host 200.1.1.10 (18 matches)
- Router#show ip cache flow
- IP packet size distribution (18 total packets):
- 1-32 64 96 128 160 192 224 256 288 320 352 384 416 448 480
- .000 .000 .000 1.00 .000 .000 .000 .000 .000 .000 .000 .000 .000 .000 .000
- 512 544 576 1024 1536 2048 2560 3072 3584 4096 4608
- .000 .000 .000 .000 .000 .000 .000 .000 .000 .000 .000
- IP Flow Switching Cache, 278544 bytes
- 1 active, 4095 inactive, 3 added
- 66 ager polls, 0 flow alloc failures
- Active flows timeout in 30 minutes
- Inactive flows timeout in 15 seconds
- last clearing of statistics never
- Protocol Total Flows Packets Bytes Packets Active(Sec) Idle(Sec)
- -------- Flows /Sec /Flow /Pkt /Sec /Flow /Flow
- ICMP 2 0.0 5 100 0.0 4.0 15.3
- Total: 2 0.0 5 100 0.0 4.0 15.3
- SrcIf SrcIPaddress DstIf DstIPaddress Pr SrcP DstP Pkts
- Et0/1 199.1.1.100 Null 200.1.1.10 01 0000 0800 18
通過效果圖我們發現,有18個數據包匹配了ACL,并被PBR牽引到null0接口后丟棄了。
PBR的相關知識就為大家介紹完了,希望大家已經掌握。
【編輯推薦】