实验三十六、策略路由(PBR)配置

一、 实验目的

1. 掌握策略路由的配置

2. 理解策略路由的原理

二、 应用环境

PBR 使得用户可以依据饿来进行路由,而不是路由协议,目前支持的策略是:ip 报文大小、

源IP 地址。

三、 实验设备

1. DCR-1751 两台

2. PC 机 两台

四、 实验拓扑

clip_image002

五、 实验要求

配置表

Router-A Router-B

F0/0 192.168.0.1/24 F0/0 192.168.2.1/24

S1/1 (DCE) 192.168.1.1/24 S1/0 192.168.1.2/24

PC SERVER

IP 192.168.0.3/24 192.168.2.2/24

网关 192.168.0.1 192.168.2.1

六、 实验步骤

第一步:参照实验三,配置所有接口地址和PC 地址,并测试连通性

第二步:配置路由器A

Router-A_config#ip access-list standard net1 !定义ACL

Router-A_config_std_nacl#permit 192.168.0.10 255.255.255.255

!设置需要进行策略路由的源地址

Router-A_config_std_nacl#exit

Router-A_config#route-map pbr 10 permit !定义route-map

Router-A_config_route_map#match ip address net1 !设定源地址

Router-A_config_route_map#set ip next-hop 192.168.1.2 !设置下一跳地址

Router-A_config_route_map#exit

Router-A_config_s1/1#int f0/0 !进入源地址的路由器接口

Router-A_config_f0/0#ip policy route-map pbr !绑定route-map

第三步:配置路由器B 的路由表

Router-B#conf

Router-B_config#ip route 192.168.0.0 255.255.255.0 192.168.1.1

第四步:查看路由器A、B 的路由表

Router-A#sh ip route

Codes: C - connected, S - static, R - RIP, B - BGP, BC - BGP connected

D - DEIGRP, DEX - external DEIGRP, O - OSPF, OIA - OSPF inter area

ON1 - OSPF NSSA external type 1, ON2 - OSPF NSSA external type 2

OE1 - OSPF external type 1, OE2 - OSPF external type 2

DHCP - DHCP type

VRF ID: 0

C 192.168.0.0/24 is directly connected, FastEthernet0/0

C 192.168.1.0/24 is directly connected, Serial1/1

!注意到没有192.168.2.0 的路由

Router-B#sh ip route

Codes: C - connected, S - static, R - RIP, B - BGP, BC - BGP connected

D - DEIGRP, DEX - external DEIGRP, O - OSPF, OIA - OSPF inter area

ON1 - OSPF NSSA external type 1, ON2 - OSPF NSSA external type 2

OE1 - OSPF external type 1, OE2 - OSPF external type 2

DHCP - DHCP type

VRF ID: 0

S 192.168.0.0/24 [1,0] via 192.168.1.1 !返回的数据包的路由

C 192.168.1.0/24 is directly connected, Serial1/0

C 192.168.2.0/24 is directly connected, FastEthernet0/0

第五步:测试

clip_image004

第六步:查看配置

Router-A#sh ip policy

Interface Route-map

FastEthernet0/0 pbr

Router-A#sh route-map

Route-map pbr, permit, sequence 10

Match clauses:

match ip address net1

Set clauses:

set ip next-hop 192.168.1.2

Exit policy:

Policy routing matches: 15 packets, 1048 bytes

Router-A#debug ip policy

Router-A#2004-1-1 00:41:44 PBR: s=192.168.0.10 (FastEthernet0/0), d=192.168.2.2 (Serial1/1),

len= 60, gate=192.168.1.2 policy routed

2004-1-1 00:41:45 PBR: s=192.168.0.10 (FastEthernet0/0), d=192.168.2.2 (Serial1/1), len= 60,

gate=192.168.1.2 policy routed

2004-1-1 00:41:46 PBR: s=192.168.0.10 (FastEthernet0/0), d=192.168.2.2 (Serial1/1), len= 60,

gate=192.168.1.2 policy routed

2004-1-1 00:41:47 PBR: s=192.168.0.10 (FastEthernet0/0), d=192.168.2.2 (Serial1/1), len= 60,

gate=192.168.1.2 policy routed

Router-A#no debug all