策略路由( PBR <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

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

二,    实现,调用 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-if)#no shut

A(config-if)#exit

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

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

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)#encap hdlc

B(config-if)#clock rate 56000

B(config-if)#no shut

B(config-if)#exit

*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

% Incomplete command.

 

B(config)#int s1/2

B(config-if)#ip addr 202.110.104.2 255.255.255.0

B(config-if)#encap hdlc

B(config-if)#clock rate 56000

B(config-if)#no shut

B(config-if)#exit

*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)#encap hdlc

C(config-if)#clock rate 56000

C(config-if)#no shut

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

% Incomplete command.

 

D(config)#int s1/1

D(config-if)#ip addr 202.110.103.2 255.255.255.0

D(config-if)#encap hdlc

D(config-if)#clock rate 56000

D(config-if)#no shut

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-if)#exit

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-if)#exit

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-if)#encap hdlc

R5(config-if)#no shut

R5(config-if)#exit

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

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

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-route-map)#exit

B(config)#access-list 1 permit 192.168.20.0 <?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />0.0.0.255

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

B(config)#int s1/0

 

 

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#

A#traceroute
 

 

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

 

 

30 网段的路由?????

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