美文网首页
【HCIP】路由控制-Traffic-Policy

【HCIP】路由控制-Traffic-Policy

作者: 周山 | 来源:发表于2021-09-11 23:35 被阅读0次

    最近加班有点多,停更了一阵子,下边继续加油产出,一起学起来!

    华为设备上如何进行策略路由的配置

    我们指定以下实验拓扑

    ,实验要求

    同样我们先把基础的路由配通,
    以R2为例;

    [Huawei]sysname R2
    [R2]int g0/0/0
    [R2-GigabitEthernet0/0/0]ip add 10.1.12.2 24
    [R2-GigabitEthernet0/0/0]int g0/0/1
    [R2-GigabitEthernet0/0/1]ip add 10.1.23.2 24
    [R2-GigabitEthernet0/0/1]int g0/0/2
    [R2-GigabitEthernet0/0/2]ip add 10.1.24.2 24
    
    

    R3

    [R3]int l 0
    [R3-LoopBack0]ip address 8.8.8.8 32
    

    R1\R4添加各自的loopback接口
    为了让我们的路由能发出去,我们配置一条

    [R1]ip route-static 0.0.0.0 0 10.1.12.2
    

    的缺省路由
    R2既没有去往8.8.8.8的路由,也没有缺省路由
    我们可以通过命令查看

    [R2]dis ip routing-table 8.8.8.8
    [R2]dis ip routing-table 0.0.0.0
    
    [R4]ip route-static 0.0.0.0 0 10.1.24.2
    

    我们在R1、R3、R4各自做路由指向回包,模拟路由预配,但是R2是没有路由表的

    • 策略路由在报文接受的路由上做策略路由,这样才能让路由通过策略正确转发。
    • 策略路由仅对穿越设备的报文生效,对设备自身产生的报文无效
    • 设备自己产生的报文需要用另一个策略路由命令

    Traffic-Policy

    • 首先使用ACL工具匹配目标流量
      为什么不能用前缀列表IP-prefix呢?
      因为acl是可以定义流量的端口号的,但是前缀列表不可以
    • 然后对目标流量定义行为,如修改下一跳
    图片.png

    基本是三段式
    1、定义流量类
    2、定义流动作
    3、定义流策略
    进入对应接口进行接口绑定inbound

    开始实验我们在R2上进行实验

    先通过acl定义流量

    [R2]acl 3000
    [R2-acl-adv-3000]rule permit tcp source 192.168.1.0 0.0.0.255 destination 8.8.8.
    8 0 destination-port eq 23
    [R2]acl 3001
    [R2-acl-adv-3001]rule permit tcp source 192.168.2.0 0.0.0.255 destination 8.8.8.
    8 0 destination-port eq 23
    
    

    在通过traffic 定义流动作分类

    [R2]traffic classifier a
    [R2-classifier-a]if-match acl 3000
    [R2-classifier-a]q
    [R2]traffic classifier b
    [R2-classifier-b]if-match acl 3001
    [R2-classifier-b]q
    

    我们回显下上边的步骤 dis cu

    traffic classifier a operator or
     if-match acl 3000
    traffic classifier b operator or
     if-match acl 3001 
    

    我们在定义了多个分类后如果每个分类里边有多个if-mach语句的话,这些if默认都是或的关系,
    or:只要匹配任意一条if-mach语句就属于定义这个类。
    and:如果我们把or改为and就是要同时匹配所有if-mach语句才属于定义的这个类
    如果报文不匹配策略路由,则按照默认基于DIP的查表转发。
    [R2]traffic classifier test operator or

    继续定义流行为

    [R2]traffic behavior a
    [R2-behavior-a]redirect ip-nexthop 10.1.23.3
    [R2-behavior-a]q
    [R2]traffic behavior b
    [R2-behavior-b]redirect ip-nexthop 10.1.24.4
    

    继续定义流策略

    [R2]traffic policy test
    [R2-trafficpolicy-test]classifier a behavior a
    [R2-trafficpolicy-test]classifier b behavior b
    

    进入对应接口进行接口绑定inbound

    [R2]int g0/0/0
    [R2-GigabitEthernet0/0/0]traffic-policy test inbound 
    

    接下来我们把R3上telnet登陆的命令敲出来

    [R3]user-interface vty 0 4
    [R3-ui-vty0-4]authentication-mode password 
    Please configure the login password (maximum length 16):huawei
    [R3-ui-vty0-4]user privilege level 3
    

    我们在R1上telnet R3

    <R1>telnet -a 192.168.1.1 8.8.8.8
      Press CTRL_] to quit telnet mode
      Trying 8.8.8.8 ...
    

    通过1.1访问应该发往23.3的接口通过23.2,但是我们发现不通。这是为什么呢?因为我们在这个网络中并没有进行任何动态路由协议的使用,我们的报文也不匹配这路由表中的任何路由,所以就不会主动的触发对直连的下一跳的解析,我们查arp表发现

    [R2]dis arp
    IP ADDRESS      MAC ADDRESS     EXPIRE(M) TYPE        INTERFACE   VPN-INSTANCE 
                                              VLAN/CEVLAN PVC                      
    ------------------------------------------------------------------------------
    10.1.12.2       00e0-fcb4-243b            I -         GE0/0/0
    10.1.23.2       00e0-fcb4-243c            I -         GE0/0/1
    10.1.24.2       00e0-fcb4-243d            I -         GE0/0/2
    ------------------------------------------------------------------------------
    Total:3         Dynamic:0       Static:0     Interface:3    
    

    所以我们需要ping一下

    <R2>ping 10.1.23.3
      PING 10.1.23.3: 56  data bytes, press CTRL_C to break
        Reply from 10.1.23.3: bytes=56 Sequence=1 ttl=255 time=230 ms
        Reply from 10.1.23.3: bytes=56 Sequence=2 ttl=255 time=40 ms
        Reply from 10.1.23.3: bytes=56 Sequence=3 ttl=255 time=30 ms
        Reply from 10.1.23.3: bytes=56 Sequence=4 ttl=255 time=30 ms
        Reply from 10.1.23.3: bytes=56 Sequence=5 ttl=255 time=20 ms
    

    发现arp没有下一跳23.3的arp缓存,再查找arp缓存

    <R2>dis arp
    IP ADDRESS      MAC ADDRESS     EXPIRE(M) TYPE        INTERFACE   VPN-INSTANCE 
                                              VLAN/CEVLAN PVC                      
    ------------------------------------------------------------------------------
    10.1.12.2       00e0-fcb4-243b            I -         GE0/0/0
    10.1.12.1       00e0-fc26-41dd  17        D-0         GE0/0/0
    10.1.23.2       00e0-fcb4-243c            I -         GE0/0/1
    10.1.23.3       00e0-fce8-43c9  20        D-0         GE0/0/1
    10.1.24.2       00e0-fcb4-243d            I -         GE0/0/2
    ------------------------------------------------------------------------------
    Total:5         Dynamic:2       Static:0     Interface:3    
    <R2>
    

    10.1.24.4同样ping操作后我们发现还是没有通
    原来我们少配置了R2上的回包路由,没有回包肯定是不通的

    [R2]ip route-static 192.168.1.0 24 10.1.12.1
    [R2]ip route-static 192.168.2.0 24 10.1.12.1
    
    <R1>telnet -a 192.168.1.1 8.8.8.8
      Press CTRL_] to quit telnet mode
      Trying 8.8.8.8 ...
      Connected to 8.8.8.8 ...
    
    Login authentication
    
    
    Password:
    <R3>
    
    <R1>telnet -a 192.168.2.1 8.8.8.8
      Press CTRL_] to quit telnet mode
      Trying 8.8.8.8 ...
      Connected to 8.8.8.8 ...
    
    Login authentication
    
    
    Password:
    <R4>
    

    试验成功!

    相关文章

      网友评论

          本文标题:【HCIP】路由控制-Traffic-Policy

          本文链接:https://www.haomeiwen.com/subject/mhxqwltx.html