• HCIP之BGP的选路原则


    目录

    HCIP之BGP的选路原则

    实验

    R1基本配置

    R2基本配置

    R3基本配置

    R4基本配置

    R5基本配置

    ospf区域配置

    AS1区域配置

    AS2区域配置

     BGP选路的原则

     1.优选PV值最大的路由

            修改PV影响选路的配置:

    2.优选LP属性值最大的路由

            通过修改LP值来影响选路

    3.自己始发的路由

    4.优选AS_PATH属性最短的路由

            AS_PATH属性进行选路时,需要注意的两点:

            干涉选路的方法

    5.优选起源码属性最优的路由。

            控制选路的方法

    6.优选MED属性值较小的路由

            干涉选路的方法

    7.EBGP对等体路由优于IBGP对等体


    HCIP之BGP的选路原则

            BGP的选路原则 --- 前提 --- 丢弃所有不可用的路由系信息

    实验

    R1基本配置

    1. [R1]display ip interface brief
    2. *down: administratively down
    3. ^down: standby
    4. (l): loopback
    5. (s): spoofing
    6. The number of interface that is UP in Physical is 4
    7. The number of interface that is DOWN in Physical is 1
    8. The number of interface that is UP in Protocol is 4
    9. The number of interface that is DOWN in Protocol is 1
    10. Interface IP Address/Mask Physical Protocol
    11. GigabitEthernet0/0/0 12.0.0.1/24 up up
    12. GigabitEthernet0/0/1 13.0.0.1/24 up up
    13. GigabitEthernet0/0/2 unassigned down down
    14. LoopBack0 1.1.1.1/24 up up(s)
    15. NULL0 unassigned up up(s)
    16. [R1]

    R2基本配置

    1. [R2]display ip interface brief
    2. *down: administratively down
    3. ^down: standby
    4. (l): loopback
    5. (s): spoofing
    6. The number of interface that is UP in Physical is 4
    7. The number of interface that is DOWN in Physical is 1
    8. The number of interface that is UP in Protocol is 4
    9. The number of interface that is DOWN in Protocol is 1
    10. Interface IP Address/Mask Physical Protocol
    11. GigabitEthernet0/0/0 12.0.0.2/24 up up
    12. GigabitEthernet0/0/1 24.0.0.1/24 up up
    13. GigabitEthernet0/0/2 unassigned down down
    14. LoopBack0 2.2.2.2/24 up up(s)
    15. NULL0 unassigned up up(s)
    16. [R2]

    R3基本配置

    1. [R3]display ip interface brief
    2. *down: administratively down
    3. ^down: standby
    4. (l): loopback
    5. (s): spoofing
    6. The number of interface that is UP in Physical is 4
    7. The number of interface that is DOWN in Physical is 1
    8. The number of interface that is UP in Protocol is 4
    9. The number of interface that is DOWN in Protocol is 1
    10. Interface IP Address/Mask Physical Protocol
    11. GigabitEthernet0/0/0 13.0.0.2/24 up up
    12. GigabitEthernet0/0/1 34.0.0.1/24 up up
    13. GigabitEthernet0/0/2 unassigned down down
    14. LoopBack0 3.3.3.3/24 up up(s)
    15. NULL0 unassigned up up(s)
    16. [R3]

    R4基本配置

    1. [R4]display ip interface brief
    2. *down: administratively down
    3. ^down: standby
    4. (l): loopback
    5. (s): spoofing
    6. The number of interface that is UP in Physical is 5
    7. The number of interface that is DOWN in Physical is 0
    8. The number of interface that is UP in Protocol is 5
    9. The number of interface that is DOWN in Protocol is 0
    10. Interface IP Address/Mask Physical Protocol
    11. GigabitEthernet0/0/0 24.0.0.2/24 up up
    12. GigabitEthernet0/0/1 34.0.0.2/24 up up
    13. GigabitEthernet0/0/2 45.0.0.1/24 up up
    14. LoopBack0 4.4.4.4/24 up up(s)
    15. NULL0 unassigned up up(s)
    16. [R4]\

    R5基本配置

    1. [R5]display ip interface brief
    2. *down: administratively down
    3. ^down: standby
    4. (l): loopback
    5. (s): spoofing
    6. The number of interface that is UP in Physical is 3
    7. The number of interface that is DOWN in Physical is 2
    8. The number of interface that is UP in Protocol is 3
    9. The number of interface that is DOWN in Protocol is 2
    10. Interface IP Address/Mask Physical Protocol
    11. GigabitEthernet0/0/0 45.0.0.2/24 up up
    12. GigabitEthernet0/0/1 unassigned down down
    13. GigabitEthernet0/0/2 unassigned down down
    14. LoopBack0 5.5.5.5/24 up up(s)
    15. NULL0 unassigned up up(s)
    16. [R5]

    ospf区域配置

    R2

    1. [R2]display ip routing-table protocol ospf
    2. Route Flags: R - relay, D - download to fib
    3. ------------------------------------------------------------------------------
    4. Public routing table : OSPF
    5. Destinations : 3 Routes : 3
    6. OSPF routing table status :
    7. Destinations : 3 Routes : 3
    8. Destination/Mask Proto Pre Cost Flags NextHop Interface
    9. 3.3.3.3/32 OSPF 10 2 D 24.0.0.2 GigabitEthernet
    10. 0/0/1
    11. 4.4.4.4/32 OSPF 10 1 D 24.0.0.2 GigabitEthernet
    12. 0/0/1
    13. 34.0.0.0/24 OSPF 10 2 D 24.0.0.2 GigabitEthernet
    14. 0/0/1
    15. OSPF routing table status :
    16. Destinations : 0 Routes : 0
    17. [R2]

    R3

    1. [R3]display ip routing-table protocol ospf
    2. Route Flags: R - relay, D - download to fib
    3. ------------------------------------------------------------------------------
    4. Public routing table : OSPF
    5. Destinations : 3 Routes : 3
    6. OSPF routing table status :
    7. Destinations : 3 Routes : 3
    8. Destination/Mask Proto Pre Cost Flags NextHop Interface
    9. 2.2.2.2/32 OSPF 10 2 D 34.0.0.2 GigabitEthernet
    10. 0/0/1
    11. 4.4.4.4/32 OSPF 10 1 D 34.0.0.2 GigabitEthernet
    12. 0/0/1
    13. 24.0.0.0/24 OSPF 10 2 D 34.0.0.2 GigabitEthernet
    14. 0/0/1
    15. OSPF routing table status :
    16. Destinations : 0 Routes : 0
    17. [R3]

    R4

    1. [R4]display ip routing-table protocol ospf
    2. Route Flags: R - relay, D - download to fib
    3. ------------------------------------------------------------------------------
    4. Public routing table : OSPF
    5. Destinations : 2 Routes : 2
    6. OSPF routing table status :
    7. Destinations : 2 Routes : 2
    8. Destination/Mask Proto Pre Cost Flags NextHop Interface
    9. 2.2.2.2/32 OSPF 10 1 D 24.0.0.1 GigabitEthernet
    10. 0/0/0
    11. 3.3.3.3/32 OSPF 10 1 D 34.0.0.1 GigabitEthernet
    12. 0/0/1
    13. OSPF routing table status :
    14. Destinations : 0 Routes : 0
    15. [R4]

    AS1区域配置

    R1

    1. [R1-bgp]display bgp routing-table
    2. BGP Local router ID is 1.1.1.1
    3. Status codes: * - valid, > - best, d - damped,
    4. h - history, i - internal, s - suppressed, S - Stale
    5. Origin : i - IGP, e - EGP, ? - incomplete
    6. Total Number of Routes: 1
    7. Network NextHop MED LocPrf PrefVal Path/Ogn
    8. *> 1.1.1.0/24 0.0.0.0 0 0 i
    9. [R1-bgp]display bgp peer
    10. BGP local router ID : 1.1.1.1
    11. Local AS number : 1
    12. Total number of peers : 2 Peers in established state : 2
    13. Peer V AS MsgRcvd MsgSent OutQ Up/Down State Pre
    14. fRcv
    15. 12.0.0.2 4 2 22 24 0 00:20:04 Established
    16. 0
    17. 13.0.0.2 4 2 21 23 0 00:19:59 Established
    18. 0
    19. [R1-bgp]

    AS2区域配置

    R2

    1. [R2]display bgp routing-table
    2. BGP Local router ID is 2.2.2.2
    3. Status codes: * - valid, > - best, d - damped,
    4. h - history, i - internal, s - suppressed, S - Stale
    5. Origin : i - IGP, e - EGP, ? - incomplete
    6. Total Number of Routes: 1
    7. Network NextHop MED LocPrf PrefVal Path/Ogn
    8. *> 1.1.1.0/24 12.0.0.1 0 0 1i
    9. [R2]display bgp peer
    10. BGP local router ID : 2.2.2.2
    11. Local AS number : 2
    12. Total number of peers : 2 Peers in established state : 2
    13. Peer V AS MsgRcvd MsgSent OutQ Up/Down State Pre
    14. fRcv
    15. 4.4.4.4 4 2 14 21 0 00:12:02 Established
    16. 0
    17. 12.0.0.1 4 1 23 22 0 00:20:50 Established
    18. 1
    19. [R2]

    R3

    1. [R3]display bgp peer
    2. BGP local router ID : 3.3.3.3
    3. Local AS number : 2
    4. Total number of peers : 2 Peers in established state : 2
    5. Peer V AS MsgRcvd MsgSent OutQ Up/Down State Pre
    6. fRcv
    7. 4.4.4.4 4 2 14 22 0 00:12:02 Established
    8. 0
    9. 13.0.0.1 4 1 24 23 0 00:21:17 Established
    10. 1
    11. [R3]display bgp routing-table
    12. BGP Local router ID is 3.3.3.3
    13. Status codes: * - valid, > - best, d - damped,
    14. h - history, i - internal, s - suppressed, S - Stale
    15. Origin : i - IGP, e - EGP, ? - incomplete
    16. Total Number of Routes: 1
    17. Network NextHop MED LocPrf PrefVal Path/Ogn
    18. *> 1.1.1.0/24 13.0.0.1 0 0 1i
    19. [R3]

    R4

    1. [R4]display bgp routing-table
    2. BGP Local router ID is 4.4.4.4
    3. Status codes: * - valid, > - best, d - damped,
    4. h - history, i - internal, s - suppressed, S - Stale
    5. Origin : i - IGP, e - EGP, ? - incomplete
    6. Total Number of Routes: 2
    7. Network NextHop MED LocPrf PrefVal Path/Ogn
    8. *>i 1.1.1.0/24 2.2.2.2 0 100 0 1i
    9. * i 3.3.3.3 0 100 0 1i
    10. [R4]display bgp peer
    11. BGP local router ID : 4.4.4.4
    12. Local AS number : 2
    13. Total number of peers : 3 Peers in established state : 3
    14. Peer V AS MsgRcvd MsgSent OutQ Up/Down State Pre
    15. fRcv
    16. 2.2.2.2 4 2 17 15 0 00:13:18 Established
    17. 1
    18. 3.3.3.3 4 2 16 14 0 00:12:46 Established
    19. 1
    20. 45.0.0.2 4 3 23 25 0 00:21:52 Established
    21. 0

     BGP选路的原则

    属性名

    传播范围默认值评判标准
    PV不传播0(0-65535)越大越优
    LPIBGP对等体之间100越大越优
    AS_PATHBGP对等体之间记录数量越少越优
    OGNbgp对等体之间根据起源类型决定I>e>?
    MEDbgp对等体之间默认继承全局路由表中的开销值越小越优

     1.优选PV值最大的路由

            PV值是华为的私有属性,可以理解为是权重,数值越大,其优先级越高,又因为他是所有选路原则中的第一条原则,所以,该属性是本设备上选路最方便的一个属性。 --- 这个属性只能在本设备上生效,他无法传递给任何BGP对等体。

    修改PV影响选路的配置:

            方法一 --- 全局修改

    1. [R4-bgp]peer 3.3.3.3 preferred-value ?
    2. INTEGER<0-65535> Preference value
    3. [R4-bgp]peer 3.3.3.3 preferred-value 100
    4. AS-path 1, origin igp, MED 0, localpref 100, pref-val 0, valid, internal, pre 255, IGP cost 1, not preferred for PreVal

    负载分担 --- 即让不同的流量走不同的线路,分担单一线路的压力

            方法二 --- 精细化控制

                    1.抓取流量

    [R4]ip ip-prefix PV permit 10.0.0.0 24

                    2.做路由策略

    1. [R4]route-policy PV permit node 10
    2. Info: New Sequence of this List.
    3. [R4-route-policy]if-match ip-prefix pv
    4. [R4-route-policy]apply preferred-value 100
    5. [R4-route-policy]q
    6. [R4]route-policy PV permit node 20 --- 配置空列表放通剩余所有流量
    7. Info: New Sequence of this List.
    8. [R4-route-policy]q

    注意:

            必须要配置空列表放通剩余所有流量

            3.在BGP中调用路由策略

    [r4-bgp]peer 3.3.3.3 route-policy PV import

    2.优选LP属性值最大的路由

            LP --- 本地优先级 --- 默认值为100,越大越优。这个属性可以再IBGP对等体之间进行传递,所以,他是AS内部选路最常用的属性。路由信息在传递给EBGP对等体时将不携带这个属性

    通过修改LP值来影响选路

            方法一 --- 全局修改

    [R3-bgp]default local-preference 200

            方法二 --- 精细化控制

                    在R3的出方向做

                    1.抓取路由

    [r3]ip ip-prefix lp permit 10.0.0.0 24

                    2.做路由策略

    1. [r3]route-policy lp permit node 10
    2. Info: New Sequence of this List.
    3. [r3-route-policy]if-match ip-prefix lp
    4. [r3-route-policy]apply local-preference 300
    5. [r3-route-policy]q
    6. [r3]route-policy lp permit node 20
    7. Info: New Sequence of this List.
    8. [r3-route-policy]q

                    3.在BGP进程中调用

    [r3-bgp]peer 4.4.4.4 route-policy lp export

    3.自己始发的路由

           自己始发的路由优先级高于对等体处学来的,自己始发的方法也存在多种,他们的优先级关系为手工聚合>自动聚合>network>import

    4.优选AS_PATH属性最短的路由

            AS_PATH属性进行选路时,需要注意的两点:

            1.我们在进行路由聚合时,如果激活AS_SET关键字之后,将不同AS的明细路由进行聚合,则我们将AS_PATH属性中携带所有明细AS的AS号,并用大括号括起来。在进行选路比较时,大括号的内容当做一个AS号来看待。

            2.在联邦时,我们联邦内部也需要使用AS_PATH来进行防环,我们使用小括号将AS号括起来,在进行选路比较时,将不计算小圆括号里的内容。

    干涉选路的方法

            在R1的出方向修改AS_PATH属性

            1.抓取路由

    [r1]ip ip-prefix as permit 10.0.0.0 24

            2.配置路由策略

    1. [r1]route-policy as permit node 10
    2. Info: New Sequence of this List.
    3. [r1-route-policy]if-match ip-prefix as
    4. [R1-route-policy]apply as-path 11 22 33 ?
    5. INTEGER<1-4294967295> AS number in asplain format (number<1-4294967295>)
    6. STRING<3-11> AS number in asdot format
    7. (number<1-65535>.number<0-65535>)
    8. additive Append to original As Number
    9. overwrite Overwrite original As Number
    10. [R1-route-policy]apply as-path 11 22 33 additive
    11. [R1]route-policy as permit node 20
    12. Info: New Sequence of this List.

    解析:

            additive               Append to original As Number --- 在原有AS_PATH属性的基础上添加配置的AS号

            overwrite              Overwrite original As Number --- 直接覆盖原有的AS_PATH属性值

            [R1-route-policy]apply as-path 11 22 33 additive  --- 建议使用添加,因为AS_PATH属性主要任务用来防止环路,将原有属性覆盖可能导致路由回传,造成环路产生

            3.在BGP中调用策略

    [R1-bgp]peer 12.0.0.2 route-policy as export 
    [r2-route-policy]apply as-path 1 1 1 additive --- 建议在AS_PATH属性中添加真实离开的AS的AS号,因为AS_PATH属性本身具有防环作用,添加AS号后可能导致路由无法发送到对应的AS当中,影响陆游的传递。AS_PATH属性在进行选路时,仅关注AS号的长短,不关注内容。

    5.优选起源码属性最优的路由。

            起源码的优先级 --- I>E>?

            OGN --- 起源码 --- I,e,?--- 用来表示路由条目的起源

                    I --- 代表该路由信息起源于IGP协议(不局限于IGP协议,包括静态,直连),代表该路由条目起源于AS内部 --- 通过network发不出来的路由信息起源码为I

                    E --- 代表该路由信息起源于EGP协议 --- EGP指的是BGP之前使用的外部网关协议

                    ?--- 通过除了以上两种方式学习到的路由 --- 重发布导入的路由起源码都是 ?

    控制选路的方法

            1.抓取路由

    [r2]ip ip-prefix ogn permit 10.0.0.0 24
            2.配置路由策略
    1. [r2]route-policy ogn permit node 10
    2. Info: New Sequence of this List.
    3. [r2-route-policy]if-match ip-prefix ogn
    4. [r2-route-policy]apply origin ?
    5. egp Remote EGP
    6. igp Local IGP
    7. incomplete Unknown heritage
    8. [r2-route-policy]apply origin incomplete
    9. [r2-route-policy]q
    10. [r2]route-policy ogn permit node 20
    11. Info: New Sequence of this List.
    12. [r2-route-policy]q

            3.在BGP中进行调用

    [r2-bgp]peer 12.0.0.1 route-policy ogn import

    6.优选MED属性值较小的路由

            MED --- 多出口鉴别属性 --- MED值默认初始值并不是0,而是继承了路由表中该路由条目的开销值,所以,他可以反应到达目标网段在本AS内部的开销值大小,通过这个参数,别的AS的流量在进入本AS时将可以选择开销值较小的入口进入。通过修改这个属性值,我们也可以影响其他AS的流量流入本AS的路径。若本地通过IBGP毒地鞥提学习到一条BGP路由,其中存在MED值,之后需要将这条路由再传递给本地的EBGP对等体,则他将不再携带这个MED值,这种设置将有可能造成选路不佳的情况。所以,讲义,如果存在多边界设备需要将路由发送给EBGP对等体关系时,需要将所有的路由信息都发布。(每台设备都需要发布)

    干涉选路的方法

            在R2配置,影响R1的选路

            1.抓取路由

    [r2]ip ip-prefix med permit 4.4.4.0 24

            2.配置路由策略

    1. [r2]route-policy med permit node 10
    2. Info: New Sequence of this List.
    3. [r2-route-policy]if-match ip-prefix med
    4. [r2-route-policy]apply cost 10
    5. [r2-route-policy]q
    6. [r2]route-policy med permit node 20
    7. Info: New Sequence of this List.
    8. [r2-route-policy]q

            3.在BGP进程中调用

    [r2-bgp]peer 12.0.0.1 route-policy med export

    注意:

            MED值影响的是别的AS的流量通过多个出口进入到本AS内部,如果流入的不是同一个AS,即收到的路由条目中AS_PATH属性最左边的AS号不同,则将不比较第六条,直接比较第七条

            [r4]ping -r -a 4.4.4.4 1.1.1.1 --- 可以记录流量流过的全过程

    7.EBGP对等体路由优于IBGP对等体

  • 相关阅读:
    C++产生未定义的行为的原因分析
    ArcGIS 高级制图技巧:1、制图表达轮廓线
    opencv连通域标记 connectedComponentsWithStats()函数
    SCI常见词汇表达
    Java并发编程—java内存模型2
    49张图带领小伙伴们体验一把 Flowable-UI
    Vue——插值操作 、动态绑定属性
    Python爬虫-某网酒店评论数据
    如何实现斗轮机与就地程控站DCS系统间远距离无线通讯?
    prometheus 告警
  • 原文地址:https://blog.csdn.net/qq_57289939/article/details/127820528