• Lab Route-map BGP


    利用route-map进行路由过滤

    R1:
    s0/0:12.1.1.1/24
    lo0:1.1.1.1/32
    R2:
    s0/0:12.1.1.2/24
    s0/1:23.1.1.2/24
    lo0:2.2.2.2/32
    R3:
    s0/0:23.1.1.3/24
    lo0:3.3.3.3/32

    下面通过两个例子来了解route-map的用法。

    例一:利用route-map使AS3只收到AS1的BGP路由。
    Step 1、配置各台路由器的IP地址,并且使用Ping命令确认各路由器的直连口的互通性。

    Step 2、在R1,R2和R2,R3之间运行EBGP,并宣告环回口。
    R1(config-if)#router bgp 1
    R1(config-router)#bgp router-id 1.1.1.1
    R1(config-router)#no au
    R1(config-router)#no sy
    R1(config-router)#neighbor 12.1.1.2 remote-as 2
    R1(config-router)#network 1.1.1.1 mask 255.255.255.255

    R2(config)#router bgp 2
    R2(config-router)#no au
    R2(config-router)#no sy
    R2(config-router)#bgp router-id 2.2.2.2
    R2(config-router)#network  2.2.2.2 mask 255.255.255.255
    R2(config-router)#nei 12.1.1.1 remote-as 1
    R2(config-router)#neighbor 23.1.1.3 remote-as 3

    R3(config)#router bgp 3
    R3(config-router)#no au
    R3(config-router)#no sy
    R3(config-router)#bgp router-id 3.3.3.3        
    R3(config-router)#neighbor 23.1.1.2 remote-as 2
    R3(config-router)#network 3.3.3.3 mask 255.255.255.255

    Step 3、在R3的in方向配置route-map过滤AS2的路由。
    R3(config)#ip as-path access-list 1 deny ^_2$
    R3(config)#ip as-path access-list 1 permit .*

    R3(config)#route-map FILTER permit 10
    R3(config-route-map)#match as-path 1

    R3(config)#router bgp 3
    R3(config-router)#neighbor 23.1.1.2 route-map FILTER in 

    Step 4、查看R3的路由表,过滤成功。
    R3#sh ip bgp 
    BGP table version is 3, local router ID is 3.3.3.3
    Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
                  r RIB-failure, S Stale
    Origin codes: i - IGP, e - EGP, ? - incomplete

       Network          Next Hop            Metric LocPrf Weight Path
    *> 1.1.1.1/32       23.1.1.2                               0 2 1 i
    *> 3.3.3.3/32       0.0.0.0                  0         32768 i

    R3#sh ip route bgp 
         1.0.0.0/32 is subnetted, 1 subnets
    B       1.1.1.1 [20/0] via 23.1.1.2, 00:01:55

    例二:利用route-map过滤指定的路由。
    Step 1、配置各台路由器的IP地址,并且使用Ping命令确认各路由器的直连口的互通性。

    Step 2、在R1,R2和R2,R3之间运行EBGP,并宣告环回口。
    R1(config-if)#router bgp 1
    R1(config-router)#bgp router-id 1.1.1.1
    R1(config-router)#no au
    R1(config-router)#no sy
    R1(config-router)#neighbor 12.1.1.2 remote-as 2
    R1(config-router)#network 1.1.1.1 mask 255.255.255.255

    R2(config)#router bgp 2
    R2(config-router)#no au
    R2(config-router)#no sy
    R2(config-router)#bgp router-id 2.2.2.2
    R2(config-router)#network  2.2.2.2 mask 255.255.255.255
    R2(config-router)#nei 12.1.1.1 remote-as 1
    R2(config-router)#neighbor 23.1.1.3 remote-as 3

    R3(config)#router bgp 3
    R3(config-router)#no au
    R3(config-router)#no sy
    R3(config-router)#bgp router-id 3.3.3.3        
    R3(config-router)#neighbor 23.1.1.2 remote-as 2
    R3(config-router)#network 3.3.3.3 mask 255.255.255.255 

    Step 3、在R3的in方向配置route-map过滤指定的路由。
    R3(config)#access-list 1 permit 1.1.1.1 0.0.0.0
    R3(config)#route-map FILTER deny 10
    R3(config-route-map)#match ip address 1
    R3(config-route-map)#exit
    R3(config)#route-map FILTER permit 20

    R3(config)#router bgp 3
    R3(config-router)#neighbor 23.1.1.2 route-map FILTER in 

    Step 4、查看R3的路由表,过滤成功。
    R3#sh ip bgp 
    BGP table version is 3, local router ID is 3.3.3.3
    Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
                  r RIB-failure, S Stale
    Origin codes: i - IGP, e - EGP, ? - incomplete

       Network          Next Hop            Metric LocPrf Weight Path
    *> 2.2.2.2/32       23.1.1.2                 0             0 2 i
    *> 3.3.3.3/32       0.0.0.0                  0         32768 i

    R3#sh ip route bgp 
         2.0.0.0/32 is subnetted, 1 subnets
    B       2.2.2.2 [20/0] via 23.1.1.2, 00:02:33

    结论:
    route-map,是将复杂if....then逻辑应用于路由器,可用于控制重分发以实现基于策略的路由选择。
    1、包含一系列match语句的指定条件。
    2、使用set语句对符合条件的分组和路由进行相应的修改措施。
    3、同一名称的路由映射表的一组语句构成一个映射表。
    4、映射表中每条语句都有一个序列号因此可单独编程,检查匹配条件时从小序列号开始,找到匹配条件后查找就立即结束。
    5、 路由映射表可使用标准ip访问列表或扩展列表,可指定源地址、目标地址、应用程序、协议类型、tos、优先级条件。
    6、仅当语句标记为permit且分组满足match 条件时才执行set命令,如果是deny时不进行策略选择而动态路由选择,否则放弃,以常规方式根据目标地址转发它。
    7、一条match语句可包含多个条件,这些条件是or关系,至少满足一个条件时才算匹配,一个路由映射表也可以有多条match语句,多条match语句的关第是and。
    8、路由映射表没有match语句时,意会所有条件都可以满足都可匹配;而没有set语句时,则不做任何措施。映射表最后隐匿了deny all语句,不匹配条件时按常规转发但不会丢弃分组,在set语句加空接口时可丢弃分组。
    9、基于策略的路由选择只影响被配置的路由——下一跳等路径,但不会影响目的地。

  • 相关阅读:
    npm run eslint 报错 (87 errors, 0 warnings potentially fixable with the --fix option.)
    vue 项目 webstrom IDE格式化代码规则遵循eslint设置
    VUE:Method definition shorthands are not supported by current JavaScript version解决办法(该方法定义的缺陷是不支持当前的JavaScript版本)
    Flex 布局全解
    前端解析ipa、apk安装包信息 —— app-info-parser
    微信小程序开发
    base64上传到oss
    jQuery 文档操作方法
    学习v-on的使用
    学习vue结合ajax查询出后台数据
  • 原文地址:https://www.cnblogs.com/cyrusxx/p/12824219.html
Copyright © 2020-2023  润新知