天天看点

CCNP精粹系列之十九--策略路由实战,博主推荐文章

                      策略路由(PBR)

一,    特性:依据包的源地址,转发数据包,//正常数据表的转发是依据“路由表中的目的路由”。

二,    实现,调用route-map表。

三,    机制,

1,         如果route-map语句选择permit参数,且和match后的条件匹配,则用set后的指定动作处理数据。

2,         如果route-map语句选择deny参数,且和match后的条件匹配,则用路由表中的路由处理数据

3,         如果route-map语句与所有条件不匹配,则用则用路由表中的路由处理数据

四,    PBR的配置;

1, 建立route-map

(config)#route-map 名   permit/deny  行号

(config-route-map)#match ip addr  访问控制列表

(config-route-map)#set   动作

///动作:

ip next-hop  下一跳 //修改下一跳

(该路由在具体路由表中存在,即具体路由)。

Ip default next-hop 下一跳ip     修改下一跳

(该路由是默认路由)

Interface  端口   修改包的流出端口(默认路由)

2,调用route-map

在流出端口上:

(config-if)ip policy route-map  名

试验环境:

假如R1是网通公司的信息网络,R4是电信公司的信息网络,21世纪的中国飞速发展,而且是全球人口最多的国家,几乎实现了人人跟信息流量打交道的社会,网络的流量是不言而喻,如果不做策略,路由的选择是默认的,可能导致某条线路的拥挤,甚至拥塞,可能导致某条线路的空闲,这样的话设备得不到合理利用,这个问题是必须要解决的。

为了解决网络流量的拥塞难题,必须采取一定的策略来要求我们的尖端设备合理利用,既可以保证信息流量的不拥塞,又可以保证网络畅通。

环境搭建:R1上做两个环回口模拟其他网段,R4上做一环回口模拟另一网段。整个环境我们采取最简单的rip协议。

IP规划:

R1:lo0  192.168.20.1      255.255.255.0

    Lo1   192.168.30.1          255.255.255.0

S1/0     202.110.100.1       255.255.255.0

     R2 :S1/0          202.110.100.2        255.255.255.0

.          S1/1            202.110.101.1        255.255.255.0

S1/2   202.110.104.2        255.255.255.0

R3:S1/1    202.110.101.2 255.255.255.0

.          S1/2   202.110.102.1 255.255.255.0

R4 :S1/2    202.110.102.2 255.255.255.0

.          S1/1  202.110.103.1 255.255.255.0

R5 :S1/1    202.110.103.2 255.255.255.0

.          S1/2  202.110.101.1 255.255.255.0

先在A路由器上做:(R1)

A>

A>EN

A#config t

Enter configuration commands, one per line.  End with CNTL/Z.

A(config)#int lo0

A(config-if)#ip addr 192.168.20.1 255.255.255.0

A(config-if)#int l01

A(config-if)#ip addr 192.168.30.1 255.255.255.0

A(config-if)#no shut

A(config-if)#exit

A(config)#int s1/0

A(config-if)#ip addr 202.110.100.1 255.255.255.0

A(config-if)#encap hdlc

A(config-if)#clock rate 56000

A(config)#router

*Apr 20 18:01:07.975: %LINK-3-UPDOWN: Interface Serial1/0, changed state to up

*Apr 20 18:01:08.979: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial1/0, changed state to up

% Incomplete command.

A(config)#

A(config)#router rip

A(config-router)#net 192.168.20.0

A(config-router)#net 192.168.30.0

A(config-router)#net 202.110.100.0

A(config-router)#

在B上配置端口路由:(R2)

Router>en

Router#config t

Router(config)#host B

B(config)#int s1/0

B(config-if)#ip addr 202.110.100.2 255.255.255.0

B(config-if)#encap hdlc

B(config-if)#no shut

B(config-if)#exit

B(config)#

*Apr 20 18:04:52.007: %LINK-3-UPDOWN: Interface Serial1/0, changed state to up

*Apr 20 18:04:53.011: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial1/0, changed state to up

B(config)#int s1/1

B(config-if)#ip addr 202.110.101.1 255.255.255.0

B(config-if)#clock rate 56000

*Apr 20 18:05:37.703: %LINK-3-UPDOWN: Interface Serial1/1, changed state to upnt

*Apr 20 18:05:38.707: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial1/1, changed state to up

B(config)#int s1/2

B(config-if)#ip addr 202.110.104.2 255.255.255.0

*Apr 20 18:06:37.579: %LINK-3-UPDOWN: Interface Serial1/2, changed state to uprip

*Apr 20 18:06:38.583: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial1/2, changed state to up

B(config-router)#router rip

B(config-router)#net 202.110.100.0

B(config-router)#net 202.110.101.0

B(config-router)#net 202.110.104.0

在C上做:(R3)

Router(config)#host C

C(config)#int s1/1

C(config-if)#ip addr 202.110.101.2 255.255.255.0

C(config-if)#encap hdlc

C(config-if)#no shut

C(config-if)#exi

C(config)#

*Apr 20 18:22:30.963: %LINK-3-UPDOWN: Interface Serial1/1, changed state to up

*Apr 20 18:22:31.967: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial1/1, changed state to up

C(config)#int s1/2

C(config-if)#ip addr 202.110.102.1 255.255.255.0

C(config-if)#clock rate 56000

C(config-if)#

*Apr 20 18:23:19.439: %LINK-3-UPDOWN: Interface Serial1/2, changed state to up

*Apr 20 18:23:20.443: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial1/2, changed state to up

C(config-if)#exit

C(config)#router rip

C(config-router)#net 202.110.101.0

C(config-router)#net 202.110.102.0

C(config-router)#

R4上做:

R4(config)#host D

D(config)#int s1/2

D(config-if)#ip addr 202.110.102.2 255.255.255.0

D(config-if)#encap hdlc

D(config-if)#no shut

D(config-if)#exit

D(config)#int s

*Apr 20 18:26:38.027: %LINK-3-UPDOWN: Interface Serial1/2, changed state to up

*Apr 20 18:26:39.031: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial1/2, changed state to up

D(config)#int s1/1

D(config-if)#ip addr 202.110.103.2 255.255.255.0

D(config-if)#clock rate 56000

D(config-if)#

*Apr 20 18:27:16.903: %LINK-3-UPDOWN: Interface Serial1/1, changed state to up

*Apr 20 18:27:17.907: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial1/1, changed state to up

D(config)#int lo0

D(config-if)#ip addr 192.168.10.0

D(config-if)#ip addr 192.168.10.1 255.255.255.0

D(config)#router rip

D(config-router)#net 192.168.10.0

D(config-router)#net 202.110.102.0

D(config-router)#net 202.110.103.0

R5上:

Router(config)#host R5

R5(config)#int s1/1

R5(config-if)#ip addr 202.110.103.2 255.255.255.0

R5(config-if)#encap hdlc

R5(config-if)#no shut

R5(config-if)#exit

R5(config-if)#int s1/2

R5(config-if)#ip addr 202.110.104.1 255.255.255.0

R5(config)#router rip

R5(config-router)#net 202.110.103.0

R5(config-router)#net 202.110.104.0

在R4上做测试:

D#show ip ro

以上是R4上在不做任何策略的情况下,路由情况,显然20和30网段的路由都是走R3和R5的路由器,这只是默认的路由走向。这样显然可能导致路由流量的拥塞,下面我们在R2上做路由策略,通过路由策略实现资源的合理分配和利用,人为使20网段的路由走R3路由器,30网段的路由走R5,如果能实现,我们的试验就成功了。

在R2上做策略:

B#config t

B(config)#route-map abc permit 10

B(config-route-map)#match ip addr 1

B(config-route-map)#set ip next-hop 202.110.101.2

B(config-route-map)#exit

B(config)#route-map abc permit 20

B(config-route-map)#match ip addr 2

B(config-route-map)#set ip next-hop 202.110.104.1

B(config)#access-list 1 permit 192.168.20.0 0.0.0.255

B(config)#access-list 2 permit 192.168.30.0 0.0.0.255

B(config-if)#ip policy route-map abc    //将map表应用到端口。

B(config-if)#

在R1上ping192.168.10.1:

A>en

A#ping 192.168.10.1

Type escape sequence to abort.

Sending 5, 100-byte ICMP Echos to 192.168.10.1, timeout is 2 seconds:

!!!!!

Success rate is 100 percent (5/5), round-trip min/avg/max = 168/380/1116 ms

没问题!!

然后在R1上做数据包的跟踪:

A#

A#traceroute

对20网段数据包分析,显然是走了R3,符合我们的计划,所以一切顺利.

30网段的路由?????

 这样就实现了控制路由线路的目的,避免了链路拥塞和不合理利用,实现的策略路由的功能。关于路由控制还有更高级的用法,请往下继续学习吧!

     本文转自shenleigang 51CTO博客,原文链接:http://blog.51cto.com/shenleigang/151698,如需转载请自行联系原作者

继续阅读