华为路由器PBR

来源:互联网 发布:piano软件全键盘 编辑:程序博客网 时间:2024/05/17 03:14

session 1 PBR

        策略路由,用于接口入方向,优先级高于路由表,如果失效才会继续匹配路由表进行转发。策略路由分为本地策略路由(只影响本路由器产生的流量)和接口策略路由(影响路由器转发的流量)。pbr影响的是数据而路由策略影响的是路由。

       以接口PBR作为实例配置,拓扑如下


        首先配置全网ospf路由协议,使全网互通。默认情况下从pc1、pc2到达pc3分别有2条负载路由,从pc3到达pc或pc2也有2条负载路由,默认配置完成后发现pc1到达pc3的路径是AR1-AR2-AR4-PC3,pc2到达pc3的路径是AR1-AR3-AR4-PC3,相反pc3到达pc1和pc2也是和pc1、pc2到达pc3 的路径一致。现在为了实现pc1到达pc3走AR1-AR3-AR4-PC3,而pc2到达pc3走AR1-AR2-AR4-PC3路径,相应的PC3返回PC1、PC2的路径也要一致,下面可以使用PBR在AR1的E4/0/0和E4/0/1以及AR4的G0/0/0接口做流量重定向从而达到上述目的。pc1:192.168.1.10/24, pc2:192.168.2.20/24 pc3:172.16.1.10/24

配置如下:

AR1上配置

acl number 3998  
 rule 1 permit ip source 192.168.2.0 0.0.0.255 
acl number 3999  
 rule 1 permit ip source 192.168.1.0 0.0.0.255 
#
traffic classifier 2 operator or                            创建的名为2的流分类,匹配acl3998的流量,模式为or或满足一项即生效
 if-match acl 3998
traffic classifier 1 operator or                            创建的名为1的刘分类,匹配acl3999的流量,模式为or或满足一项即生效
 if-match acl 3999
#
traffic behavior 2 创建名为2的流行为,指定动作为对匹配的流量进行下一跳重定向
 redirect ip-nexthop 12.1.1.2
traffic behavior 1 创建名为1的流行为,指定动作为对匹配的流量进行下一跳重定向
 redirect ip-nexthop 13.1.1.3
#
traffic policy 12 创建名为12的流策略,关联流分类和流行为
 classifier 1 behavior 1
 classifier 2 behavior 2
#

interface Ethernet4/0/0
 ip address 192.168.1.1 255.255.255.0 
 traffic-policy 12 inbound 将流策略应用于接口in方向pbr
#
interface Ethernet4/0/1
 ip address 192.168.2.1 255.255.255.0 

 traffic-policy 12 inbound将流策略应用于接口in方向pbr
#
interface GigabitEthernet0/0/0
 ip address 12.1.1.1 255.255.255.0 
#
interface GigabitEthernet0/0/1
 ip address 13.1.1.1 255.255.255.0 
#

ospf 1 router-id 1.1.1.1 
 area 0.0.0.0 
  network 12.1.1.1 0.0.0.0 
  network 13.1.1.1 0.0.0.0 
  network 192.168.1.1 0.0.0.0 
  network 192.168.2.1 0.0.0.0 
#

AR2上配置

interface GigabitEthernet0/0/0
 ip address 12.1.1.2 255.255.255.0 
#
interface GigabitEthernet0/0/1
 ip address 24.1.1.2 255.255.255.0 
#
interface GigabitEthernet0/0/2
#
interface NULL0
#
ospf 1 router-id 2.2.2.2 
 area 0.0.0.0 
  network 12.1.1.2 0.0.0.0 
  network 24.1.1.2 0.0.0.0 
#

AR3上配置

interface GigabitEthernet0/0/1
 ip address 13.1.1.3 255.255.255.0 
#
interface GigabitEthernet0/0/2
 ip address 34.1.1.3 255.255.255.0 
#
interface NULL0
#
ospf 1 router-id 3.3.3.33 
 area 0.0.0.0 
  network 13.1.1.3 0.0.0.0 
  network 34.1.1.3 0.0.0.0 
#

AR4上配置

acl number 3998  创建了目的地址的acl,应用于匹配目的地址
 rule 1 permit ip destination 192.168.2.0 0.0.0.255 
acl number 3999  
 rule 1 permit ip destination 192.168.1.0 0.0.0.255 
#
traffic classifier 2 operator or
 if-match acl 3998
traffic classifier 1 operator or
 if-match acl 3999
#
traffic behavior 2
 redirect ip-nexthop 24.1.1.2
traffic behavior 1
 redirect ip-nexthop 34.1.1.3
#
traffic policy 12
 classifier 1 behavior 1
 classifier 2 behavior 2
#

interface GigabitEthernet0/0/0
 ip address 172.16.1.1 255.255.255.0 

  traffic-policy 12 inbound
#
interface GigabitEthernet0/0/1
 ip address 24.1.1.4 255.255.255.0 

#
interface GigabitEthernet0/0/2
 ip address 34.1.1.4 255.255.255.0 

#
interface NULL0
#
ospf 1 router-id 4.4.4.4 
 area 0.0.0.0 
  network 24.1.1.4 0.0.0.0 
  network 34.1.1.4 0.0.0.0 
  network 172.16.1.1 0.0.0.0 
#

检查配置正确

[AR1]display traffic policy user-defined 12
  User Defined Traffic Policy Information:
  Policy: 12
   Classifier: 1
    Operator: OR
     Behavior: 1
      Redirect: 
        Redirect ip-nexthop 13.1.1.3
   Classifier: 2
    Operator: OR
     Behavior: 2
      Redirect: 
        Redirect ip-nexthop 12.1.1.2
[AR1]

<AR4>display traffic policy user-defined 12
  User Defined Traffic Policy Information:
  Policy: 12
   Classifier: 1
    Operator: OR
     Behavior: 1
      Redirect: 
        Redirect ip-nexthop 34.1.1.3
   Classifier: 2
    Operator: OR
     Behavior: 2
      Redirect: 
        Redirect ip-nexthop 24.1.1.2
<AR4>

检查PBR是否配置成功,实现了pc3走AR1-AR3-AR4-PC3,pc2到达pc3走AR1-AR2-AR4-PC3路径,PC3返回流量路径也相同。

PC1>tracert 172.16.1.10
traceroute to 172.16.1.10, 8 hops max
(ICMP), press Ctrl+C to stop
 1  192.168.1.1   16 ms  15 ms  <1 ms
 2  13.1.1.3   16 ms  31 ms  16 ms
 3  34.1.1.4   31 ms  16 ms  31 ms
 4    *172.16.1.10   31 ms  16 ms
PC1>

PC2>tracert 172.16.1.10
traceroute to 172.16.1.10, 8 hops max
(ICMP), press Ctrl+C to stop
 1  192.168.2.1   15 ms  <1 ms  16 ms
 2  12.1.1.2   15 ms  16 ms  31 ms
 3  24.1.1.4   16 ms  15 ms  32 ms
 4  172.16.1.10   15 ms  31 ms  16 ms
PC2>

PC3>tracert 192.168.1.10
traceroute to 192.168.1.10, 8 hops max
(ICMP), press Ctrl+C to stop
 1  172.16.1.1   16 ms  <1 ms  15 ms
 2  34.1.1.3   32 ms  15 ms  31 ms
 3  13.1.1.1   16 ms  16 ms  31 ms
 4    *192.168.1.10   16 ms  31 ms
PC3>tracert 192.168.2.20
traceroute to 192.168.2.20, 8 hops max
(ICMP), press Ctrl+C to stop
 1  172.16.1.1   16 ms  <1 ms  16 ms
 2  24.1.1.2   15 ms  16 ms  31 ms
 3  12.1.1.1   16 ms  31 ms  15 ms
 4    *192.168.2.20   31 ms  31 ms
PC3>


0 0