淺析PBR(基于策略的路由)
PBR(基于策略的路由)概述
基于策略的路由(PBR)是一種靈活的數(shù)據(jù)包路由轉(zhuǎn)發(fā)機(jī)制。通過在路由器上應(yīng)用策略路由,使路由器根據(jù)路由映射(route-map)決定經(jīng)過路由器的數(shù)據(jù)包如何處理。路由映射決定了一個數(shù)據(jù)包的下一跳轉(zhuǎn)發(fā)路由器。
在路由器上應(yīng)用策略路由,必須要指定策略路由使用的路由映射(route-map),并且要創(chuàng)建路由映射。一個路由映射由很多條策略組成,每個策略都定義了1個或多個匹配規(guī)則和對應(yīng)操作。一個接口應(yīng)用策略路由后,將對該接口收到的所有包進(jìn)行檢查,不符合路由映射中所定義的數(shù)據(jù)包將會被按照正常路由轉(zhuǎn)發(fā)進(jìn)行處理,符合路由映射中的策略的數(shù)據(jù)包,就按照策略中定義的操作進(jìn)行處理。
策略路由主要應(yīng)用在企業(yè)路由表復(fù)雜或者需要對路由進(jìn)行控制的情況下,特別是當(dāng)企業(yè)網(wǎng)絡(luò)出口有兩條,需要對不同服務(wù)和應(yīng)用或者不同客戶端的路由進(jìn)行控制時,當(dāng)然企業(yè)內(nèi)部運(yùn)行兩個網(wǎng)絡(luò)或者更多的網(wǎng)絡(luò)時也經(jīng)常要用到路由策略;另外,策略路由除了應(yīng)用在非正常的路由選路之外,它還可以用來防止病毒或黑客的攻擊,使用條件語句將病毒或攻擊的特征碼匹配出來,然后再指定一個安全策略(如使用黑洞路由)將攻擊阻斷.
黑洞路由是對動態(tài)路由選擇協(xié)議的一個補(bǔ)充。黑洞路由可以將不想要的流量轉(zhuǎn)發(fā)到一個稱為null0的接口中去。我們可以建立一條或一些靜態(tài)路由,將精確匹配這些路由的流量丟棄。和ACL不同的是,Cisco IOS的所有交換過程,包括CEF,都能處理黑洞路由,而不降低性能。需要注意的是,PBR技術(shù)不支持配置了PBR的路由器始發(fā)流量和到達(dá)該路由器的流量。
PBR(基于策略的路由)實(shí)例解析
下面我們就以一個試驗(yàn)來描述策略路由的阻斷流量的功能。路由器的E0/0口作為內(nèi)部網(wǎng)絡(luò)的網(wǎng)關(guān),地址為200.1.1.1,內(nèi)部網(wǎng)絡(luò)有一個WWW服務(wù)器,地址為200.1.1.100,和WWW同一網(wǎng)段內(nèi)有普通用戶PC一臺,在外部網(wǎng)絡(luò)有一個遠(yuǎn)程的用戶,IP地址為199.1.1.100,允許遠(yuǎn)程用戶能夠訪問WWW服務(wù)器,同時不允許訪問內(nèi)部用戶的PC機(jī),使用PBR完成需求。
在路由器上配置相關(guān)的地址,并測試與200.1.1.100,200.1.1.10和199.1.1.100的連通性。配置一個路由映射(route-map),匹配從遠(yuǎn)程用戶到內(nèi)部用戶的流量,并牽引到null0接口中去,并在null0接口下配置不返回不可達(dá)信息。其他不匹配路由映射的流量正常轉(zhuǎn)發(fā)。
#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交換功能,方便我們對結(jié)果進(jìn)行查看,并在該接口上調(diào)用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
- 在遠(yuǎn)程主機(jī)上對內(nèi)網(wǎng)的設(shè)備再次進(jìn)行連通性測試:
- 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),
這時,會發(fā)現(xiàn)外部網(wǎng)絡(luò)的遠(yuǎn)程用戶已經(jīng)無法ping通內(nèi)部的用戶了,但是還是可以ping通WWW服務(wù)器。查看邊界路由器的狀態(tài):
- 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
通過效果圖我們發(fā)現(xiàn),有18個數(shù)據(jù)包匹配了ACL,并被PBR牽引到null0接口后丟棄了。
PBR的相關(guān)知識就為大家介紹完了,希望大家已經(jīng)掌握。
【編輯推薦】