基於策略的路由(PBR)簡介

來源:互聯網
上載者:User

基於策略的路由(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介面下配置不返回不可達資訊。其他不匹配路由映射的流量正常轉寄。

路由器的初始配置如下:

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.

更多精彩內容:http://www.bianceng.cnhttp://www.bianceng.cn/Network/lyjs/

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的相關知識就為大家介紹完了,希望大家已經掌握。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.