二、知识点:
BGP路由优选规则
当到达同一个目的网段存在多条路由时,BGP通过如下的次序进行路由优选:
1)丢弃下一跳不可达的路由。
2)优选Preferred-Value属性值最大的路由。
3)优选Local_Preference属性值最大的路由。
4)本地始发的BGP路由优于从其他对等体学习到的路由,本地始发的路由优先级:优选手动聚合>自动聚合>network>import>从对等体学到的。
5)优选AS_Path属性值最短的路由。
6)优选Origin属性最优的路由。Origin属性值按优先级从高到低的排列是:IGP、EGP及Incomplete。
7)优选MED属性值最小的路由。
8)优选从EBGP对等体学来的路由(EBGP路由优先级高于IBGP路由)。
9)优选到Next_Hop的IGP度量值最小的路由。
10)优选Cluster_List最短的路由。
11)优选Router ID(Orginator_ID)最小的设备通告的路由。
12)优选具有最小IP地址的对等体通告的路由。
1,丢弃下一跳不可达路由
2, 优选Preferred-Value属性值最大的路由。
协议优选值 属性为 华为的私有属性,默认值为0 ,值越大越有 ,只在本地设备有效。
3,优选Local_Preference属性值最大的路由。
本地优先级应用于 对等体之间 ,值越大越优,默认值为100 。

- [R1]undo acl 2000
- [R1]undo route-policy wt
- [R1]bgp 100
- [R1-bgp]undo peer 10.10.3.3 route-policy wt import
-
- 1)用地址前缀列表 抓取需要修改属性的路由
- [R3]ip ip-prefix cw index 10 permit 200.1.1.0 24
- 2)用路由策略修改匹配条件的 路由属性 本地优先级的值
- [R3]route-policy wt permit node 10
- [R3-route-policy]if-match ip-prefix cw
- [R3-route-policy]apply local-preference 1000
- [R3-route-policy]q
- [R3]route-policy wt permit node 20
- 3) 在向邻居1.1 发送路由的出向调用策略,生效,实现R1上路由优选
- [R3]bgp 100
- [R3-bgp]peer 10.10.1.1 route-policy wt export
- 4)[R1]dis bgp routing-table
- BGP Local router ID is 1.1.1.1
- Status codes: * - valid, > - best, d - damped,
- h - history, i - internal, s - suppressed, S - Stale
- Origin : i - IGP, e - EGP, ? - incomplete
- Total Number of Routes: 2
- Network NextHop MED LocPrf PrefVal Path/Ogn
- *>i 200.1.1.0 10.10.3.3 0 1000 0 200i
- ●i 10.10.2.2 0 100 0 200i
- 4,本地始发的BGP路由优于从其他对等体学习到的路由,本地始发的路由优先级:优选手动聚合>自动聚合>network>import>从对等体学到的。
- [R3]undo ip ip-prefix cw
- [R3]undo route-policy wt
- [R3]bgp 100
- [R3-bgp]undo peer 10.10.1.1 route-policy wt export
- 在R1 创建一条 lo1 : 100.1.1.1 /24 ,使用network 和import 向BGP 注入100.1.1.0/24 的路由
- ip route-static 100.1.1.0 25 null 0
- ip route-static 100.1.1.0 26 null 0
- ip route-static 100.1.1.0 27 null 0
- 通过引入上面的静态路由 ,进行聚合 ,聚合 100.1.1.0 /24 的路由
- [R1]interface LoopBack 1
- [R1-LoopBack1]ip add 100.1.1.1 24
- [R1-LoopBack1]q
- [R1]ip route-static 100.1.1.0 25 NULL 0
- [R1]ip route-static 100.1.1.0 26 NULL 0
- [R1]ip route-static 100.1.1.0 27 NULL 0
- [R1]bgp 100
- [R1-bgp]network 100.1.1.0 24
- [R1-bgp]import-route direct
- [R1-bgp]import-route static
- [R1]dis bgp routing-table
- BGP Local router ID is 1.1.1.1
- Status codes: * - valid, > - best, d - damped,
- h - history, i - internal, s - suppressed, S - Stale
- Origin : i - IGP, e - EGP, ? - incomplete
- Total Number of Routes: 16
- Network NextHop MED LocPrf PrefVal Path/Ogn
- *> 10.10.1.0/24 0.0.0.0 0 0 ?
- *> 10.10.1.1/32 0.0.0.0 0 0 ?
- *> 100.1.1.0/24 0.0.0.0 0 0 i
- ●0.0.0.0 0 0 ?
- 通过上述信息,表明 network > import
- 接下来将注入BGP 的具有相同前缀的静态路由进行手动聚合:
- [R1]bgp 100
- [R1-bgp]aggregate 100.1.1.0 24
- [R1]dis bgp routing-table
- BGP Local router ID is 1.1.1.1
- Status codes: * - valid, > - best, d - damped,
- h - history, i - internal, s - suppressed, S - Stale
- Origin : i - IGP, e - EGP, ? - incomplete
- Total Number of Routes: 17
- Network NextHop MED LocPrf PrefVal Path/Ogn
- *> 10.10.1.0/24 0.0.0.0 0 0 ?
- *> 10.10.1.1/32 0.0.0.0 0 0 ?
- *> 100.1.1.0/24 127.0.0.1 0 ? //手动聚合得来的路由
- ●0.0.0.0 0 0 i //network 进来的路由
- ●0.0.0.0 0 0 ? //import 进来的路由
- *> 100.1.1.0/25 0.0.0.0 0 0 ?
- *> 100.1.1.0/26 0.0.0.0 0 0 ?
- *> 100.1.1.0/27 0.0.0.0 0 0 ?
- [R1]bgp 100
- [R1-bgp]summary automatic //自动聚合 ,聚合默认掩码
- [R1]dis bgp routing-table
- BGP Local router ID is 1.1.1.1
- Status codes: * - valid, > - best, d - damped,
- h - history, i - internal, s - suppressed, S - Stale
- Origin : i - IGP, e - EGP, ? - incomplete
- Total Number of Routes: 19
- Network NextHop MED LocPrf PrefVal Path/Ogn
- *> 10.0.0.0 127.0.0.1 0 ?
- s> 10.10.1.0/24 0.0.0.0 0 0 ?
- *> 10.10.1.1/32 0.0.0.0 0 0 ?
- *> 100.0.0.0 127.0.0.1 0 ? //自动聚合 100.0.0.0 /8
- *> 100.1.1.0/24 127.0.0.1 0 ?
- ●0.0.0.0 0 0 i
- ●0.0.0.0 0 0 ?
- s> 100.1.1.0/25 0.0.0.0 0 0 ?
- [R1]bgp 100
- [R1-bgp]aggregate 100.0.0.0 8 //手动聚合 100.0.0.0 /8
- [R1]dis bgp routing-table
- BGP Local router ID is 1.1.1.1
- Status codes: * - valid, > - best, d - damped,
- h - history, i - internal, s - suppressed, S - Stale
- Origin : i - IGP, e - EGP, ? - incomplete
- Total Number of Routes: 20
- Network NextHop MED LocPrf PrefVal Path/Ogn
- *> 10.0.0.0 127.0.0.1 0 ?
- s> 10.10.1.0/24 0.0.0.0 0 0 ?
- *> 10.10.1.1/32 0.0.0.0 0 0 ?
- *> 100.0.0.0 127.0.0.1 0 ? //手动聚合
- ●127.0.0.1 0 ? //自动聚合 ,区分不开?
- [R1]dis bgp routing-table 100.0.0.0 8 //查看具体 100.0.0.0 8 的路由信息,来区分手动和自动谁优先
- BGP local router ID : 1.1.1.1
- Local AS number : 100
- Paths: 2 available, 1 best, 1 select
- BGP routing table entry information of 100.0.0.0/8:
- Aggregated route.
- Route Duration: 00h00m48s
- Direct Out-interface: NULL0
- Original nexthop: 127.0.0.1
- Qos information : 0x0
- AS-path Nil, origin incomplete, pref-val 0, valid, local, best, select, active,
- pre 255
- Aggregator: AS 100, Aggregator ID 1.1.1.1
- Advertised to such 2 peers: //手动聚合路由通告给邻居
- 10.10.3.3
- 10.10.2.2
- BGP routing table entry information of 100.0.0.0/8:
- Summary automatic route
- Route Duration: 00h01m48s
- Direct Out-interface: NULL0
- Original nexthop: 127.0.0.1
- Qos information : 0x0
- AS-path Nil, origin incomplete, pref-val 0, valid, local, pre 255, not preferre
- d for route type
- Aggregator: AS 100, Aggregator ID 1.1.1.1
- Not advertised to any peer yet //自动聚合路由不通告
- 通过以上整体操作验证: 本地产生的路由 手动聚合 > 自动聚合 > network > import >对等体学习来
-
- [R1]bgp 100
- [R1-bgp]undo summary automatic //关闭自动聚合
- [R1-bgp]aggregate 100.1.1.0 24 //手动聚合 掩码24网段
- [R1]dis bgp routing-table
- BGP Local router ID is 1.1.1.1
- Status codes: * - valid, > - best, d - damped,
- h - history, i - internal, s - suppressed, S - Stale
- Origin : i - IGP, e - EGP, ? - incomplete
- Total Number of Routes: 18
- Network NextHop MED LocPrf PrefVal Path/Ogn
- *> 10.10.1.0/24 0.0.0.0 0 0 ?
- *> 10.10.1.1/32 0.0.0.0 0 0 ?
- *> 100.0.0.0 127.0.0.1 0 ?
- *> 100.1.1.0/24 127.0.0.1 0 ? //手动聚合优先
- ●0.0.0.0 0 0 i
- ●0.0.0.0 0 0 ?
- *> 100.1.1.0/25 0.0.0.0 0 0 ? //明细路由
- *> 100.1.1.0/26 0.0.0.0 0 0 ?
- *> 100.1.1.0/27 0.0.0.0 0 0 ?
- 在邻居设备查看BGP路由表,发现 聚合路由传递给邻居的同时,明细路由也传递给邻居啦 ?
- [R2]dis bgp routing-table
- BGP Local router ID is 2.2.2.2
- Status codes: * - valid, > - best, d - damped,
- h - history, i - internal, s - suppressed, S - Stale
- Origin : i - IGP, e - EGP, ? - incomplete
- Total Number of Routes: 9
- Network NextHop MED LocPrf PrefVal Path/Ogn
- *>i 10.10.1.0/24 10.10.1.1 0 100 0 ?
- *>i 100.0.0.0 10.10.1.1 100 0 ?
- *>i 100.1.1.0/24 10.10.1.1 100 0 ?
- *>i 100.1.1.0/25 10.10.1.1 0 100 0 ?
- *>i 100.1.1.0/26 10.10.1.1 0 100 0 ?
- *>i 100.1.1.0/27 10.10.1.1 0 100 0 ?
- *>i 192.168.12.0 10.10.1.1 0 100 0 ?
- *>i 192.168.13.0 10.10.1.1 0 100 0 ?
- *> 200.1.1.0 192.168.24.4 0 0 200i
- 进行手动聚合之后,不向邻居发送明细路由,所以要进行明细抑制。
- [R1]bgp 100
- [R1-bgp]aggregate 100.1.1.0 24 detail-suppressed
- [R1-bgp]q
- [R1]dis bgp routing-table
- BGP Local router ID is 1.1.1.1
- Status codes: * - valid, > - best, d - damped,
- h - history, i - internal, s - suppressed, S - Stale
- Origin : i - IGP, e - EGP, ? - incomplete
- Total Number of Routes: 18
- Network NextHop MED LocPrf PrefVal Path/Ogn
- *> 10.10.1.0/24 0.0.0.0 0 0 ?
- *> 10.10.1.1/32 0.0.0.0 0 0 ?
- *> 100.0.0.0 127.0.0.1 0 ?
- *> 100.1.1.0/24 127.0.0.1 0 ?
- ●0.0.0.0 0 0 i
- ●0.0.0.0 0 0 ?
- s> 100.1.1.0/25 0.0.0.0 0 0 ? //s 表示抑制
- s> 100.1.1.0/26 0.0.0.0 0 0 ?
- s> 100.1.1.0/27 0.0.0.0 0 0 ?
- *> 100.1.1.1/32 0.0.0.0 0 0 ?
- *> 127.0.0.0 0.0.0.0 0 0 ?
- *> 127.0.0.1/32 0.0.0.0 0 0 ?
- *> 192.168.12.0 0.0.0.0 0 0 ?
- *> 192.168.12.1/32 0.0.0.0 0 0 ?
- *> 192.168.13.0 0.0.0.0 0 0 ?
- *> 192.168.13.1/32 0.0.0.0 0 0 ?
- *>i 200.1.1.0 10.10.2.2 0 100 0 200i
- ●i 10.10.3.3 0 100 0 200i
- 再到邻居设备查看BGP 路由表
- [R2]dis bgp routing-table
- BGP Local router ID is 2.2.2.2
- Status codes: * - valid, > - best, d - damped,
- h - history, i - internal, s - suppressed, S - Stale
- Origin : i - IGP, e - EGP, ? - incomplete
- Total Number of Routes: 6
- Network NextHop MED LocPrf PrefVal Path/Ogn
- *>i 10.10.1.0/24 10.10.1.1 0 100 0 ?
- *>i 100.0.0.0 10.10.1.1 100 0 ?
- *>i 100.1.1.0/24 10.10.1.1 100 0 ? //发现明细路由被抑制啦
- *>i 192.168.12.0 10.10.1.1 0 100 0 ?
- *>i 192.168.13.0 10.10.1.1 0 100 0 ?
- *> 200.1.1.0 192.168.24.4 0 0 200i
- 新需求: 传递给邻居路由时,除了聚合路由,还将部分明细路由传递过去
- [R1]ip route-static 100.1.1.0 25 NULL 0
- [R1]ip route-static 100.1.1.0 26 NULL 0 —不允许掩码26明细路由传递给邻居(路由策略工具可以实现过滤)
- [R1]ip route-static 100.1.1.0 27 NULL 0
- 1)用地址前缀列表精确匹配掩码26的路由
- [R1]ip ip-prefix 26 index 10 permit 100.1.1.0 24 greater-equal 26 less-equal 26
- 2)用路由策略实现过滤,只要匹配前缀列表,就允许策略
- [R1]route-policy 25 permit node 10
- [R1-route-policy]if-match ip-prefix 26
- [R1-route-policy]q
- 3)在手动聚合的时候调用抑制策略,所以掩码26的路由就不会发送给邻居了啊
- [R1]bgp 100
- [R1-bgp]aggregate 100.1.1.0 24 suppress-policy 25
- [R1-bgp]q
- [R1]dis bgp routing-table
- BGP Local router ID is 1.1.1.1
- Status codes: * - valid, > - best, d - damped,
- h - history, i - internal, s - suppressed, S - Stale
- Origin : i - IGP, e - EGP, ? - incomplete
- Total Number of Routes: 18
- Network NextHop MED LocPrf PrefVal Path/Ogn
- *> 10.10.1.0/24 0.0.0.0 0 0 ?
- *> 10.10.1.1/32 0.0.0.0 0 0 ?
- *> 100.0.0.0 127.0.0.1 0 ?
- *> 100.1.1.0/24 127.0.0.1 0 ?
- ●0.0.0.0 0 0 i
- ●0.0.0.0 0 0 ?
- *> 100.1.1.0/25 0.0.0.0 0 0 ?
- s> 100.1.1.0/26 0.0.0.0 0 0 ?
- *> 100.1.1.0/27 0.0.0.0 0 0 ?
- *> 100.1.1.1/32 0.0.0.0 0 0 ?
- *> 127.0.0.0 0.0.0.0 0 0 ?
- *> 127.0.0.1/32 0.0.0.0 0 0 ?
- *> 192.168.12.0 0.0.0.0 0 0 ?
- *> 192.168.12.1/32 0.0.0.0 0 0 ?
- *> 192.168.13.0 0.0.0.0 0 0 ?
- *> 192.168.13.1/32 0.0.0.0 0 0 ?
- *>i 200.1.1.0 10.10.2.2 0 100 0 200i
- ●i 10.10.3.3 0 100 0 200i
- 5)优选AS_Path属性值最短的路由。
- AS 之间防环
- 路径优选 -列表越短越优
- [R1]undo ip ip-prefix 26
- [R1]undo route-policy 25
- [R1]bgp 100
- [R1-bgp]undo aggregate 100.1.1.0 24 suppress-policy 25
- [R1]bgp 100
- [R1-bgp]undo import-route direct
- [R1-bgp]undo import-route static
- [R1-bgp]undo network 100.1.1.0 24
- 1)配置地址前缀列表,抓取需要修改属性的路由
- [R2]ip ip-prefix 200 index 10 permit 200.1.1.0 24 greater-equal 24 less-equal 24
- 2)配置路由策略,给匹配的路由,修改属性值
- [R2]route-policy 200 permit node 10
- [R2-route-policy]if-match ip-prefix 200
- [R2-route-policy]apply as-path 300 additive
- [R2-route-policy]q
- [R2]route-policy 200 permit node 20 //放行没有匹配的其他路由
- 3)在与R1建立邻居的出方向调用策略
- [R2]bgp 100
- [R2-bgp]peer 10.10.1.1 route-policy 200 export
- [R2-bgp]q
- 4)[R1]dis bgp routing-table
- BGP Local router ID is 1.1.1.1
- Status codes: * - valid, > - best, d - damped,
- h - history, i - internal, s - suppressed, S - Stale
- Origin : i - IGP, e - EGP, ? - incomplete
- Total Number of Routes: 2
- Network NextHop MED LocPrf PrefVal Path/Ogn
- *>i 200.1.1.0 10.10.3.3 0 100 0 200i
- ●i 10.10.2.2 0 100 0 300 200i
- 6)优选Origin属性最优的路由。Origin属性值按优先级从高到低的排列是:IGP、EGP及Incomplete。
- i > e > ?
- 7)优选MED属性值最小的路由。
- 应用于AS 之间 , 从一个AS 传递过来带有MED 的路由,这个MED值这个属性不会再传递给第三个AS , MED 默认 0 ,值 越大越不优 。 用来选择AS 入向最优的路由
- [R2]undo ip ip-prefix 200
- [R2]undo route-policy 200
- [R2]bgp 100
- [R2-bgp]undo peer 10.10.1.1 route-policy 200 export
- [R1]bgp 100
- [R1-bgp]network 100.1.1.0 24
- [R1-bgp]q
- [R4]dis bgp routing-table
- BGP Local router ID is 4.4.4.4
- Status codes: * - valid, > - best, d - damped,
- h - history, i - internal, s - suppressed, S - Stale
- Origin : i - IGP, e - EGP, ? - incomplete
- Total Number of Routes: 6
- Network NextHop MED LocPrf PrefVal Path/Ogn
- *> 100.1.1.0/24 192.168.24.2 0 100i
- 192.168.34.3 0 100i
- 1)配置地址前缀列表,抓取需要修改属性的路由
- [R2]ip ip-prefix 100 index 10 permit 100.1.1.0 24
- 2)配置路由策略,给匹配的路由,修改属性值
- [R2]route-policy 100 permit node 10
- [R2-route-policy]if-match ip-prefix 100
- [R2-route-policy]apply cost 100
- [R2-route-policy]q
- [R2]route-policy 100 permit node 20
- 3)在与R4建立邻居的出方向调用策略
- [R2]bgp 100
- [R2-bgp]peer 192.168.24.4 route-policy 100 export
- 在R4上 通过在R2上修改过的MED 值 ,来改变 R4访问R1 上100段的 选路
- [R4]dis bgp routing-table
- BGP Local router ID is 4.4.4.4
- Status codes: * - valid, > - best, d - damped,
- h - history, i - internal, s - suppressed, S - Stale
- Origin : i - IGP, e - EGP, ? - incomplete
- Total Number of Routes: 5
- Network NextHop MED LocPrf PrefVal Path/Ogn
- *> 10.10.4.0/24 0.0.0.0 0 0 i
- *> 100.0.0.0 192.168.34.3 0 100i
- *> 100.1.1.0/24 192.168.34.3 0 100i
- ●192.168.24.2 100 0 100i
- *> 200.1.1.0 0.0.0.0 0 0 i