速码!!!BGP最全学习笔记:BGP选路原则实验配置

实验1:BGP选路原则

1. 实验目的
  1. 熟悉BGP的选路的应用场景
  2. 掌握BGP的选路的配置方法
2. 实验拓扑

实验拓扑如图所示:

速码!!!BGP最全学习笔记:BGP选路原则实验配置_第1张图片

 想要华为数通配套实验拓扑和配置笔记的朋友们点赞+关注,评论区留下邮箱发给你!                 

3. 实验步骤

(1)配置IP地址

R1的配置

system-view

Enter system view, return user view with Ctrl+Z.

[Huawei]undo info-center enable

Info: Information center is disabled.

[Huawei]sysname R1

[R1]interface LoopBack 0

[R1-LoopBack0]ip address 1.1.1.1 32

[R1-LoopBack0]quit

[R1]interface g0/0/0

[R1-GigabitEthernet0/0/0]ip address 12.1.1.1 24

[R1-GigabitEthernet0/0/0]quit

[R1]interface g0/0/1

[R1-GigabitEthernet0/0/1]ip address 13.1.1.1 24

[R1-GigabitEthernet0/0/1]quit

R2的配置

system-view

Enter system view, return user view with Ctrl+Z.

[Huawei]undo info-center enable

Info: Information center is disabled.

[Huawei]sysname R2

[R2]interface LoopBack 0

[R2-LoopBack0]ip address 2.2.2.2 32

[R2-LoopBack0]quit

[R2]interface g0/0/1

[R2-GigabitEthernet0/0/1]ip address 12.1.1.2 24

[R2-GigabitEthernet0/0/1]quit

[R2]interface g0/0/0

[R2-GigabitEthernet0/0/0]ip address 24.1.1.2 24

[R2-GigabitEthernet0/0/0]quit

R3的配置

system-view

Enter system view, return user view with Ctrl+Z.

[Huawei]undo info-center enable

Info: Information center is disabled.

[Huawei]sysname R3

[R3]interface LoopBack 0

[R3-LoopBack0]ip address 3.3.3.3 32

[R3-LoopBack0]quit

[R3]interface g0/0/0

[R3-GigabitEthernet0/0/0]ip address 13.1.1.3 24

[R3-GigabitEthernet0/0/0]quit

[R3]interface g0/0/1

[R3-GigabitEthernet0/0/1]ip address 35.1.1.3 24

[R3-GigabitEthernet0/0/1]quit

R4的配置

system-view

Enter system view, return user view with Ctrl+Z.

[Huawei]undo info-center enable

Info: Information center is disabled.

[Huawei]sysname R4

[R4]interface LoopBack 0

[R4-LoopBack0]ip address 4.4.4.4 32

[R4-LoopBack0]quit

[R4]interface g0/0/1

[R4-GigabitEthernet0/0/1]ip address 24.1.1.4 24

[R4-GigabitEthernet0/0/1]quit

[R4]interface g0/0/0

[R4-GigabitEthernet0/0/0]ip address 46.1.1.4 24

[R4-GigabitEthernet0/0/0]quit

R5的配置

system-view

Enter system view, return user view with Ctrl+Z.

[Huawei]undo info-center enable

Info: Information center is disabled.

[Huawei]sysname R5

[R5]interface LoopBack 0

[R5-LoopBack0]ip address 5.5.5.5 32

[R5-LoopBack0]quit

[R5]interface g0/0/0

[R5-GigabitEthernet0/0/0]ip address 35.1.1.5 24

[R5-GigabitEthernet0/0/0]quit

[R5]interface g0/0/1

[R5-GigabitEthernet0/0/1]ip address 56.1.1.5 24

[R5-GigabitEthernet0/0/1]quit

R6的配置

system-view

Enter system view, return user view with Ctrl+Z.

[Huawei]undo info-center enable

Info: Information center is disabled.

[Huawei]sysname R6

[R6]interface g0/0/1

[R6-GigabitEthernet0/0/1]ip address 46.1.1.6 24

[R6-GigabitEthernet0/0/1]quit

[R6]interface g0/0/0

[R6-GigabitEthernet0/0/0]ip address 56.1.1.6 24

[R6-GigabitEthernet0/0/0]quit

[R6]interface LoopBack 0

[R6-LoopBack0]ip ad

[R6-LoopBack0]ip address 6.6.6.6 32

[R6-LoopBack0]quit

想要华为数通配套实验拓扑和配置笔记的朋友们点赞+关注,评论区留下邮箱发给你!

(2) 配置IGP

R4的配置

[R4]ospf router-id 4.4.4.4

[R4-ospf-1]area 0

[R4-ospf-1-area-0.0.0.0]network 46.1.1.0 0.0.0.255

[R4-ospf-1-area-0.0.0.0]network 4.4.4.4 0.0.0.0

[R4-ospf-1-area-0.0.0.0]quit

R5的配置

[R5]ospf router-id 5.5.5.5

[R5-ospf-1]area 0

[R5-ospf-1-area-0.0.0.0]network 56.1.1.0 0.0.0.255

[R5-ospf-1-area-0.0.0.0]network 5.5.5.5 0.0.0.0

[R5-ospf-1-area-0.0.0.0]quit

R6的配置

[R6]ospf router-id 6.6.6.6

[R6-ospf-1]area 0

[R6-ospf-1-area-0.0.0.0]network 46.1.1.0 0.0.0.255

[R6-ospf-1-area-0.0.0.0]network 56.1.1.0 0.0.0.255

[R6-ospf-1-area-0.0.0.0]network 6.6.6.6 0.0.0.0

[R6-ospf-1-area-0.0.0.0]quit

(3) 配置IBGP

R4的配置

[R4]bgp 456

[R4-bgp]undo synchronization

[R4-bgp]undo summary automatic

[R4-bgp]router-id 4.4.4.4

[R4-bgp]peer 6.6.6.6 as-number 456

[R4-bgp]peer 6.6.6.6 connect-interface LoopBack 0

[R5-bgp]peer 6.6.6.6 next-hop-local

R5的配置

[R5]bgp 456

[R5-bgp]undo synchronization

[R5-bgp]undo summary automatic

[R5-bgp]router-id 5.5.5.5

[R5-bgp]peer 6.6.6.6 as-number 456

[R5-bgp]peer 6.6.6.6 connect-interface LoopBack 0

[R4-bgp]peer 6.6.6.6 next-hop-local

R6的配置

[R6]bgp 456

[R6-bgp]undo synchronization

[R6-bgp]undo summary automatic

[R6-bgp]router-id 6.6.6.6

[R6-bgp]peer 4.4.4.4 as-number 456

[R6-bgp]peer 4.4.4.4 connect-interface LoopBack 0

[R6-bgp]peer 5.5.5.5 as-number 456

[R6-bgp]peer 5.5.5.5 connect-interface LoopBack 0

[R6-bgp]quit

想要华为数通配套实验拓扑和配置笔记的朋友们点赞+关注,评论区留下邮箱发给你!

(4) 配置EBGP

R1的配置

[R1]bgp 100

[R1-bgp]undo summary automatic

[R1-bgp]undo synchronization

[R1-bgp]router-id 1.1.1.1

[R1-bgp]peer 12.1.1.2 as-number 200

[R1-bgp]peer 13.1.1.3 as-number 300

[R1-bgp]quit

R2的配置

[R2]bgp 200

[R2-bgp]undo synchronization

[R2-bgp]undo summary automatic

[R2-bgp]router-id 2.2.2.2

[R2-bgp]peer 12.1.1.1 as-number 100

[R2-bgp]peer 24.1.1.4 as-number 456

[R2-bgp]quit

R3的配置

[R3]bgp 300

[R3-bgp]undo synchronization

[R3-bgp]undo summary automatic

[R3-bgp]router-id 3.3.3.3

[R3-bgp]peer 13.1.1.1 as-number 100

[R3-bgp]peer 35.1.1.5 as-number 456

R4的配置

[R4]bgp 456

[R4-bgp]peer 24.1.1.2 as-number 200

[R4-bgp]quit

R5的配置

[R5]bgp 456

[R5-bgp]peer 35.1.1.3 as-number 300

[R5-bgp]quit

(5)宣告路由

[R1]bgp 100

[R1-bgp]network 1.1.1.1 32

[R1-bgp]quit

(6)在R6上查看BGP的路由表

display bgp routing-table

 BGP Local router ID is 6.6.6.6

 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  1.1.1.1/32         4.4.4.4                    100        0      200 100i

 * i                     5.5.5.5                    100        0      300

通过以上输出可以看到,R6选择的来自R4的路由

(7)在R6上查看1.1.1.1这条路由的详细信息

display bgp routing-table 1.1.1.1 32

 BGP local router ID : 6.6.6.6

 Local AS number : 456

 Paths:   2 available, 1 best, 1 select  

 BGP routing table entry information of 1.1.1.1/32:

 From: 4.4.4.4 (4.4.4.4)   //从R4过来的路由

 Route Duration: 00h04m41s  

 Relay IP Nexthop: 46.1.1.4

 Relay IP Out-Interface: GigabitEthernet0/0/1

 Original nexthop: 4.4.4.4

 Qos information : 0x0

 AS-path 200 100, origin igp, localpref 100, pref-val 0, valid, internal, best, select, active, pre 255, IGP cost 1

 Not advertised to any peer yet

 BGP routing table entry information of 1.1.1.1/32:

 From: 5.5.5.5 (5.5.5.5)    //从R5过来的路由

 Route Duration: 00h00m39s  

 Relay IP Nexthop: 56.1.1.5

 Relay IP Out-Interface: GigabitEthernet0/0/0

 Original nexthop: 5.5.5.5

 Qos information : 0x0

 AS-path 300 100, origin igp, localpref 100, pref-val 0, valid, internal, pre 255, IGP cost 1, not preferred for router ID   //没有被选中是因为rouer-id的原因

 Not advertised to any peer yet

通过以上输出可以看到,R5传递过来的路由没有选中的原因是因为它的router-id比R4的router-id大

想要华为数通配套实验拓扑和配置笔记的朋友们点赞+关注,评论区留下邮箱发给你!

4. 实验调试

(1)设置路由优选原则第11条:优选具有最小IP地址的对等体通告的路由。

  • 把R5的BGP的router-id改成4.4.4.4

[r5]bgp 456

[r5-bgp]router-id 4.4.4.4

Warning: Changing the parameter in this command resets the peer session. Continue?[Y/N]:y

[r5-bgp]quit

  • 在R6上查看1.1.1.1路由的详细信息

[r6]display bgp routing-table 1.1.1.1

 BGP local router ID : 6.6.6.6

 Local AS number : 456

 Paths:   2 available, 1 best, 1 select

 BGP routing table entry information of 1.1.1.1/32:

 From: 4.4.4.4 (4.4.4.4)

 Route Duration: 00h58m32s  

 Relay IP Nexthop: 46.1.1.4

 Relay IP Out-Interface: GigabitEthernet0/0/1

 Original nexthop: 4.4.4.4

 Qos information : 0x0

 AS-path 200 100, origin igp, localpref 100, pref-val 0, valid, internal, best, select, active, pre 255, IGP cost 1

 Not advertised to any peer yet

 BGP routing table entry information of 1.1.1.1/32:

 From: 5.5.5.5 (4.4.4.4)

 Route Duration: 00h01m55s  

 Relay IP Nexthop: 56.1.1.5

 Relay IP Out-Interface: GigabitEthernet0/0/0

 Original nexthop: 5.5.5.5

 Qos information : 0x0

 AS-path 300 100, origin igp, localpref 100, pref-val 0, valid, internal, pre 255, IGP cost 1, not preferred for peer address

 Not advertised to any peer yet

通过以上输出可以看到,R6优选R4传过来的路由, 因为R4是通过4.4.4.4与R6建立的邻居关系,R5是通过5.5.5.5与R6建立的邻居关系,4.4.4.4<5.5.5.5所以选择了R4传过来的路由。

(2)设置路由优选原则第10条:优选Router ID(Orginator_ID)最小的设备通告的路由。

  • 把R5的router-id改成5.5.5.5

[r5]bgp 456

[r5-bgp]router-id 5.5.5.5

Warning: Changing the parameter in this command resets the peer session. Continue?[Y/N]:y

[r5-bgp]quit

  • 在R6上查看1.1.1.1路由的详细

[r6]display bgp routing-table 1.1.1.1

 BGP local router ID : 6.6.6.6

 Local AS number : 456

 Paths:   2 available, 1 best, 1 select

 BGP routing table entry information of 1.1.1.1/32:

 From: 4.4.4.4 (4.4.4.4)

 Route Duration: 00h10m59s  

 Relay IP Nexthop: 46.1.1.4

 Relay IP Out-Interface: GigabitEthernet0/0/1

 Original nexthop: 4.4.4.4

 Qos information : 0x0

 AS-path 200 100, origin igp, localpref 100, pref-val 0, valid, internal, best, select, active, pre 255, IGP cost 1

 Not advertised to any peer yet

 BGP routing table entry information of 1.1.1.1/32:

 From: 5.5.5.5 (5.5.5.5)

 Route Duration: 00h00m19s  

 Relay IP Nexthop: 56.1.1.5

 Relay IP Out-Interface: GigabitEthernet0/0/0

 Original nexthop: 5.5.5.5

 Qos information : 0x0

 AS-path 300 100, origin igp, localpref 100, pref-val 0, valid, internal, pre 255, IGP cost 1, not preferred for router ID

 Not advertised to any peer yet

通过以上输出可以看到,路由优选R4传递过来的路由,因为R4的router-id为4.4.4.4,R5的router-id为5.5.5.5,所以选择了R4传递过来的路由,R5传递过来的路由没有被优选是因为router-id太大了

(3)设置路由优选原则第9条:优选Cluster_List最短的路由。

  • 把R6设置为路由反射器,让R4为它的客户端,

[r6]bgp 456

[r6-bgp]peer 4.4.4.4 reflect-client

[r6-bgp]quit

  • R4和R5用环回口建立IBGP的邻居关系,

R4的配置

[R4]bgp 456

[R4-bgp]peer 5.5.5.5 as-number 456

[R4-bgp]peer 5.5.5.5 connect-interface LoopBack 0

[R4-bgp]peer 5.5.5.5 next-hop-local

R5的配置

[r5]bgp 456

[r5-bgp]peer 4.4.4.4 as-number 456

[r5-bgp]peer 4.4.4.4 connect-interface LoopBack 0

  • 在R2宣告2.2.2.2

[r2]bgp 200

[r2-bgp]network 2.2.2.2 32

[r2-bgp]quit

  • 在R5上查看2.2.2.2的BGP明细路由

[r5]display bgp routing-table 2.2.2.2

 BGP local router ID : 5.5.5.5

 Local AS number : 456

 Paths:   3 available, 1 best, 1 select

 BGP routing table entry information of 2.2.2.2/32:

 From: 4.4.4.4 (4.4.4.4)

 Route Duration: 00h08m01s  

 Relay IP Nexthop: 56.1.1.6

 Relay IP Out-Interface: GigabitEthernet0/0/1

 Original nexthop: 4.4.4.4

 Qos information : 0x0

 AS-path 200, origin igp, MED 0, localpref 100, pref-val 0, valid, internal, best, select, active, pre 255, IGP cost 2

 Advertised to such 1 peers:

    35.1.1.3

 BGP routing table entry information of 2.2.2.2/32:

 From: 6.6.6.6 (6.6.6.6)

 Route Duration: 00h17m32s  

 Relay IP Nexthop: 56.1.1.6

 Relay IP Out-Interface: GigabitEthernet0/0/1

 Original nexthop: 4.4.4.4

 Qos information : 0x0

 AS-path 200, origin igp, MED 0, localpref 100, pref-val 0, valid, internal, pre 255, IGP cost 2, not preferred for Cluster List

 Originator:  4.4.4.4

 Cluster list: 6.6.6.6

 Not advertised to any peer yet

 BGP routing table entry information of 2.2.2.2/32:

 From: 35.1.1.3 (3.3.3.3)

 Route Duration: 00h05m56s                

 Direct Out-interface: GigabitEthernet0/0/0

 Original nexthop: 35.1.1.3

 Qos information : 0x0

 AS-path 300 100 200, origin igp, pref-val 0, valid, external, pre 255, not preferred for AS-Path

 Not advertised to any peer yet

通过以上输出可以看到,R5收到了三条关于2.2.2.2的路由,它选择了R4传递过来的路由,R6传递过来的路由没有被优选是因为cluster-list比R4传递过来的路由长(R4传递过来的路由为0),R3的路由不是最优的原因是AS-PATH(这里我们不讨论)

  • 为了不影响下面的实验步骤我们删除 R4和R5的对等体关系、在R2上取消宣告2.2.2.2这条路由,取消RR的设置

 [R4]bgp 456

[R4-bgp]undo peer 5.5.5.5 enable  //关闭R4的邻居关系

[R4-bgp]quit

[r2]bgp 200

[r2-bgp]undo network 2.2.2.2 32

[r2-bgp]quit

[r6]bgp 456

[r6-bgp]undo peer 4.4.4.4 reflect-client

[r6-bgp]qui

(4)设置路由优选原则第8条:优选到Next_Hop的IGP度量值最小的路由。

  • 在R6上查看OSPF的路由表

[r6]display ospf routing

         OSPF Process 1 with Router ID 6.6.6.6

                  Routing Tables

 Routing for Network

 Destination        Cost  Type       NextHop         AdvRouter       Area

 6.6.6.6/32         0     Stub       6.6.6.6         6.6.6.6         0.0.0.0

 46.1.1.0/24        1     Transit    46.1.1.6        6.6.6.6         0.0.0.0

 56.1.1.0/24        1     Transit    56.1.1.6        6.6.6.6         0.0.0.0

 4.4.4.4/32         1     Stub       46.1.1.4        4.4.4.4         0.0.0.0

 5.5.5.5/32         1     Stub       56.1.1.5        5.5.5.5         0.0.0.0

 9.9.9.9/32         1     Stub       46.1.1.4        4.4.4.4         0.0.0.0

 Total Nets: 6  

 Intra Area: 6  Inter Area: 0  ASE: 0  NSSA: 0

通过以上输出可以看到R6上去4.4.4.4和5.5.5.5的开销都为1

  • 修改R6的接口的OSPF的COST为100

[r6]interface g0/0/1

[r6-GigabitEthernet0/0/1]ospf cost 100   //修改OSPF的开销值为100

[r6-GigabitEthernet0/0/1]quit

  • 在R6上再次查看OSPF的路由表

[r6]display ospf routing

         OSPF Process 1 with Router ID 6.6.6.6

                  Routing Tables

 Routing for Network

 Destination        Cost  Type       NextHop         AdvRouter       Area

 6.6.6.6/32         0     Stub       6.6.6.6         6.6.6.6         0.0.0.0

 46.1.1.0/24        100   Transit    46.1.1.6        6.6.6.6         0.0.0.0

 56.1.1.0/24        1     Transit    56.1.1.6        6.6.6.6         0.0.0.0

 4.4.4.4/32         100   Stub       46.1.1.4        4.4.4.4         0.0.0.0

 5.5.5.5/32         1     Stub       56.1.1.5        5.5.5.5         0.0.0.0

 9.9.9.9/32         100   Stub       46.1.1.4        4.4.4.4         0.0.0.0

 Total Nets: 6  

 Intra Area: 6  Inter Area: 0  ASE: 0  NSSA: 0

通过以上输出可以看到4.4.4.4的路由开销为100

  • 在R6上查看1.1.1.1的BGP路由表的详细信息

[r6]display bgp routing-table 1.1.1.1

 BGP local router ID : 6.6.6.6

 Local AS number : 456

 Paths:   2 available, 1 best, 1 select

 BGP routing table entry information of 1.1.1.1/32:

 From: 5.5.5.5 (5.5.5.5)

 Route Duration: 00h29m09s  

 Relay IP Nexthop: 56.1.1.5

 Relay IP Out-Interface: GigabitEthernet0/0/0

 Original nexthop: 5.5.5.5

 Qos information : 0x0

 AS-path 300 100, origin igp, localpref 100, pref-val 0, valid, internal, best, select, active, pre 255, IGP cost 1

 Not advertised to any peer yet

 BGP routing table entry information of 1.1.1.1/32:

 From: 4.4.4.4 (4.4.4.4)

 Route Duration: 00h47m12s  

 Relay IP Nexthop: 46.1.1.4

 Relay IP Out-Interface: GigabitEthernet0/0/1

 Original nexthop: 4.4.4.4

 Qos information : 0x0

 AS-path 200 100, origin igp, localpref 100, pref-val 0, valid, internal, pre 255, IGP cost 100, not preferred for IGP cost

 Not advertised to any peer yet

通过以上输出可以看到BGP路由的下一跳,4.4.4.4的COST为100,5.5.5.5的COST为1,

所以优选R5传递过来的路由

(5)设置路由优选原则第7条:优选从EBGP对等体学来的路由(EBGP路由优先级高于IBGP路由)。

  • 查看R6的BGP路由表

[r6]display bgp routing-table

 BGP Local router ID is 6.6.6.6

 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  1.1.1.1/32         5.5.5.5                    100        0      300 100i

 * i                     4.4.4.4                    100        0      200 100i

通过以上输出可以看到R6优选了R5传递过来的路由

  • 把R6设置成为RR,让R4成为它的客户端

[r6]bgp 456

[r6-bgp]peer 4.4.4.4 reflect-client

[r6-bgp]quit

通过以上步骤R6中关于1.1.1.1这条路由就传递给了R4

  • 在R4上查看BGP路由表

display 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: 2

      Network            NextHop        MED        LocPrf    PrefVal Path/Ogn

 *>   1.1.1.1/32         24.1.1.2                              0      200 100i

 * i                     5.5.5.5                    100        0      300 100i

通过以上输出可以看到R4收到关于1.1.1.1的路由有2条,一条是通过R2(为R4的EBGP邻居)传递过来的,一条路由是通过R6(为R4的IBGP邻居)传递过来的,

  • 在R4上查看BGP的1.1.1.1这条路由的详细信息

display bgp routing-table 1.1.1.

 BGP local router ID : 4.4.4.4

 Local AS number : 456

 Paths:   2 available, 1 best, 1 select

 BGP routing table entry information of 1.1.1.1/32:

 From: 24.1.1.2 (2.2.2.2)

 Route Duration: 02h01m40s  

 Direct Out-interface: GigabitEthernet0/0/1

 Original nexthop: 24.1.1.2

 Qos information : 0x0

 AS-path 200 100, origin igp, pref-val 0, valid, external, best, select, active, pre 255

 Advertised to such 1 peers:

    6.6.6.6

 BGP routing table entry information of 1.1.1.1/32:

 From: 6.6.6.6 (6.6.6.6)

 Route Duration: 00h04m13s  

 Relay IP Nexthop: 46.1.1.6

 Relay IP Out-Interface: GigabitEthernet0/0/0

 Original nexthop: 5.5.5.5

 Qos information : 0x0

 AS-path 300 100, origin igp, localpref 100, pref-val 0, valid, internal, pre 255, IGP cost 2, not preferred for peer type

 Originator:  5.5.5.5

 Cluster list: 6.6.6.6

 Not advertised to any peer yet

通过以上输出可以看到R4选择了R2传递过来的路由,没有选择R6传递过来的路由是因为R4与R6它们为IBGP邻居关系,而R4与R2为EBGP邻居关系。

(6)设置路由优选原则第6条:优选MED属性值最小的路由。

  • 在R6上查看BGP的路由表

display bgp routing-table

 BGP Local router ID is 6.6.6.6

 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  1.1.1.1/32         5.5.5.5                    100        0      300 100i

 * i                     4.4.4.4                    100        0      200 100i

  • 把从R5传递过来的路由的MED改成800

[r5]ip ip-prefix 1.1 permit 1.1.1.1 32

[r5]route-policy med permit node 10

[r5-route-policy]if-match ip-prefix 1.1  

[r5-route-policy]apply cost 800

[r5-route-policy]quit

[r5]bgp 456

[r5-bgp]peer 35.1.1.3 route-policy med import

[r5-bgp]quit

  • 在R6上查看BGP的路由表

display bgp routing-table

 BGP Local router ID is 6.6.6.6

 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  1.1.1.1/32         5.5.5.5         800        100        0      300 100i

 * i                     4.4.4.4                    100        0      200 100i

通过以上输出可以看到R5传递过的路由它的MED为800

  • 在R6上查看1.1.1.1的BGP路由的详细信息

display bgp routing-table 1.1.1.1

 BGP local router ID : 6.6.6.6

 Local AS number : 456

 Paths:   2 available, 1 best, 1 select

 BGP routing table entry information of 1.1.1.1/32:

 From: 5.5.5.5 (5.5.5.5)

 Route Duration: 00h02m46s  

 Relay IP Nexthop: 56.1.1.5

 Relay IP Out-Interface: GigabitEthernet0/0/0

 Original nexthop: 5.5.5.5

 Qos information : 0x0

 AS-path 300 100, origin igp, MED 800, localpref 100, pref-val 0, valid, internal, best, select, active, pre 255, IGP cost 1

 Advertised to such 1 peers:

    4.4.4.4

 BGP routing table entry information of 1.1.1.1/32:

 RR-client route.

 From: 4.4.4.4 (4.4.4.4)

 Route Duration: 01h38m05s  

 Relay IP Nexthop: 46.1.1.4

 Relay IP Out-Interface: GigabitEthernet0/0/1

 Original nexthop: 4.4.4.4

 Qos information : 0x0

 AS-path 200 100, origin igp, localpref 100, pref-val 0, valid, internal, pre 255, IGP cost 100, not preferred for IGP cost

 Not advertised to any peer yet

通过以上输出可以看到虽然R5传递过来的路由的MED为800,但是它还是最优的,这个因为默认情况下MED只会在同一个AS里面比较

  • 在R6上设置MED

[r6]bgp 456

[r6-bgp]compare-different-as-med  //来自不同的AS也可以比较MED

  • 在R6上查看1.1.1.1的BGP路由的详细信息

[r6]display bgp routing-table 1.1.1.1

 BGP local router ID : 6.6.6.6

 Local AS number : 456

 Paths:   2 available, 1 best, 1 select

 BGP routing table entry information of 1.1.1.1/32:

 RR-client route.

 From: 4.4.4.4 (4.4.4.4)

 Route Duration: 01h42m06s  

 Relay IP Nexthop: 46.1.1.4

 Relay IP Out-Interface: GigabitEthernet0/0/1

 Original nexthop: 4.4.4.4

 Qos information : 0x0

 AS-path 200 100, origin igp, localpref 100, pref-val 0, valid, internal, best, select, active, pre 255, IGP cost 100

 Advertised to such 1 peers:

    5.5.5.5

 BGP routing table entry information of 1.1.1.1/32:

 From: 5.5.5.5 (5.5.5.5)

 Route Duration: 00h06m47s  

 Relay IP Nexthop: 56.1.1.5

 Relay IP Out-Interface: GigabitEthernet0/0/0

 Original nexthop: 5.5.5.5

 Qos information : 0x0

 AS-path 300 100, origin igp, MED 800, localpref 100, pref-val 0, valid, internal, pre 255, IGP cost 1, not preferred for MED

 Not advertised to any peer yet

通过以上输出可以看到R5传递过来的路由是因为MED没有被优选

想要华为数通配套实验拓扑和配置笔记的朋友们点赞+关注,评论区留下邮箱发给你!

(7)设置路由优选原则第5条:优选Origin属性最优的路由。Origin属性值按优先级从高到低的排列是:IGP、EGP及Incomplete。

  • 查看R6的BGP路由表

[r6]display bgp routing-table

 BGP Local router ID is 6.6.6.6

 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  1.1.1.1/32         4.4.4.4                    100        0      200 100i

 * i                     5.5.5.5         800        100        0      300 100i

通过以上输出可以看到R6优选了从R4传递过来的路由

  • 在R4上把路由的起源改成incomplete

[R4]ip ip-prefix 1.1 permit 1.1.1.1 32

[R4]route-policy orgin permit node 10

[R4-route-policy]if-match ip-prefix 1.1

[R4-route-policy]apply origin incomplete

[R4-route-policy]quit

[R4]bgp 456

[R4-bgp]peer 6.6.6.6 route-policy orgin export

[R4-bgp]quit

  • 查看R6的BGP路由表

[r6]display bgp routing-table

 BGP Local router ID is 6.6.6.6

 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  1.1.1.1/32         5.5.5.5         800        100        0      300 100i

 * i                     4.4.4.4                    100        0      200 100?

通过以上输出可以看到4.4.4.4传递过来的路由的起源变成了?

  • 在R6上查看1.1.1.1的BGP路由详细信息

[r6]display bgp routing-table 1.1.1.1

 BGP local router ID : 6.6.6.6

 Local AS number : 456

 Paths:   2 available, 1 best, 1 select

 BGP routing table entry information of 1.1.1.1/32:

 From: 5.5.5.5 (5.5.5.5)

 Route Duration: 00h24m39s  

 Relay IP Nexthop: 56.1.1.5

 Relay IP Out-Interface: GigabitEthernet0/0/0

 Original nexthop: 5.5.5.5

 Qos information : 0x0

 AS-path 300 100, origin igp, MED 800, localpref 100, pref-val 0, valid, internal, best, select, active, pre 255, IGP cost 1

 Advertised to such 1 peers:

    4.4.4.4

 BGP routing table entry information of 1.1.1.1/32:

 RR-client route.

 From: 4.4.4.4 (4.4.4.4)

 Route Duration: 00h07m55s  

 Relay IP Nexthop: 46.1.1.4

 Relay IP Out-Interface: GigabitEthernet0/0/1

 Original nexthop: 4.4.4.4

 Qos information : 0x0

 AS-path 200 100, origin incomplete, localpref 100, pref-val 0, valid, internal, pre 255, IGP cost 100, not preferred for Origin

 Not advertised to any peer yet

通过以上输出可以看到R4传递过来的路由没有被优选是因为起源

想要华为数通配套实验拓扑和配置笔记的朋友们点赞+关注,评论区留下邮箱发给你!

(8)设置路由优选原则第4条: 优选AS_Path属性值最短的路由。

  • 查看R6的BGP路由表

[r6]display bgp routing-table

 BGP Local router ID is 6.6.6.6

 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  1.1.1.1/32         5.5.5.5         800        100        0      300 100i

 * i                     4.4.4.4                    100        0      200 100?

通过以上输出可以看到R6优选了R5传递过来的路由

  • 在R6上把AS-PATH改成 500 600 700 800

[r6]ip ip-prefix 1.1 permit 1.1.1.1 32

[r6]route-policy as-path permit node 10

[r6-route-policy]if-match ip-prefix 1.1

[r6-route-policy]apply as-path 600 700 additive

[r6-route-policy]quit

[r6]bgp 456

[r6-bgp]peer 5.5.5.5 route-policy as-path import

[r6-bgp]quit

  • 查看R6的BGP路由表

[r6]display bgp routing-table

 BGP Local router ID is 6.6.6.6

 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  1.1.1.1/32         4.4.4.4                    100        0      200 100?

 * i                     5.5.5.5         800        100        0      600 700 300 100i

通过以上输出可以看到R5传递过来的路由它的AS-PATH变成了600 700 300 100

  • 在R6上查看BGP路由表1.1.1.1的详细信息

[r6]display bgp routing-table 1.1.1.1

 BGP local router ID : 6.6.6.6

 Local AS number : 456

 Paths:   2 available, 1 best, 1 select

 BGP routing table entry information of 1.1.1.1/32:

 RR-client route.

 From: 4.4.4.4 (4.4.4.4)

 Route Duration: 00h14m40s  

 Relay IP Nexthop: 46.1.1.4

 Relay IP Out-Interface: GigabitEthernet0/0/1

 Original nexthop: 4.4.4.4

 Qos information : 0x0

 AS-path 200 100, origin incomplete, localpref 100, pref-val 0, valid, internal, best, select, active, pre 255, IGP cost 100

 Advertised to such 1 peers:

    5.5.5.5

 BGP routing table entry information of 1.1.1.1/32:

 From: 5.5.5.5 (5.5.5.5)

 Route Duration: 00h02m08s  

 Relay IP Nexthop: 56.1.1.5

 Relay IP Out-Interface: GigabitEthernet0/0/0

 Original nexthop: 5.5.5.5

 Qos information : 0x0

 AS-path 600 700 300 100, origin igp, MED 800, localpref 100, pref-val 0, valid, internal, pre 255, IGP cost 1, not preferred for AS-Path

 Not advertised to any peer yet

通过以上输出可以看到R5传递过来的路由没有被优选是因为AS-PATH的原因

(9)设置路由优选原则第3条: 本地始发的BGP路由优于从其他对等体学习到的路由,本地始发的路由优先级:优选手动聚合>自动聚合>network>import>从对等体学到的。

  • 在R1上把环回口的路由改为1.1.1.1/24并且在BGP中宣告

[R1]interface LoopBack 0

[R1-LoopBack0]ip address 8.8.8.8 24

[R1-LoopBack0]quit

[R1]bgp 100

[R1-bgp]network 8.8.8.0 255.255.255.0

[R1-bgp]quit

  • 在R3上查看BGP的路由表

[r3]display bgp routing-table

 BGP Local router ID is 3.3.3.3

 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

 *>   1.1.1.1/32         13.1.1.1        0                     0      100i

 *>   8.8.8.0/24         13.1.1.1        0                     0      100i

通过以上输出可以看到8.8.8.0的路由在BGP的路由表中了

  • 在R3上设置两条静态路由指向NULL0,并在导入到BGP中,然后手动聚合

[r2]ip route-static 8.8.8.0 255.255.255.128 NULL 0

[r3]ip route-static 8.8.8.128 255.255.255.128 NULL 0

[r3]bgp 456

[r3-bgp]aggregate 8.8.8.0 255.255.255.0 detail-suppressed

[r3-bgp]import-route static

在R3上查看BGP的路由表

[r3]display bgp routing-table

 BGP Local router ID is 3.3.3.3

 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

 *>   1.1.1.1/32         13.1.1.1        0                     0      100i

 *>   8.8.8.0/24         127.0.0.1                             0      ?

 *                       13.1.1.1        0                     0      100i

 s>   8.8.8.0/25         0.0.0.0         0                     0      ?

 s>   8.8.8.128/25       0.0.0.0         0                     0      ?

通过以上输出可以看到选择了手动聚合的,

  • 在R3上查看8.8.8.0 255.255.255.0的详细路由

[r3]display bgp routing-table 8.8.8.0 255.255.255.0

 BGP local router ID : 3.3.3.3

 Local AS number : 300

 Paths:   2 available, 1 best, 1 select

 BGP routing table entry information of 8.8.8.0/24:

 Aggregated route.

 Route Duration: 00h06m08s  

 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 300, Aggregator ID 3.3.3.3, Atomic-aggregate

 Advertised to such 2 peers:

    13.1.1.1

    35.1.1.5

 BGP routing table entry information of 8.8.8.0/24:

 From: 13.1.1.1 (1.1.1.1)

 Route Duration: 00h22m22s  

 Direct Out-interface: GigabitEthernet0/0/0

 Original nexthop: 13.1.1.1

 Qos information : 0x0

 AS-path 100, origin igp, MED 0, pref-val 0, valid, external, pre 255, not preferred for route type

 Not advertised to any peer yet

(10)设置路由优选原则第2条: 优选Local_Preference属性值最大的路由。

查看R6的BGP路由表

display bgp routing-table

 BGP Local router ID is 6.6.6.6

 Status codes: * - valid, > - best, d - damped,

               h - history,  i - internal, s - suppressed, S - Stale

               Origin : i - IGP, e - EGP, ? - incomplete

 Total Number of Routes: 3

      Network            NextHop        MED        LocPrf    PrefVal Path/Ogn

 *>i  1.1.1.1/32         4.4.4.4                    100        0      200 100?

 * i                     5.5.5.5         800        100        0      600 700 300 100i

 *>i  8.8.8.0/24         5.5.5.5                    100        0      300?

通过以上输出可以看到关于1.1.1.1这条路由优选从R4传递过来的

在R6上把R5传递过来的路由的本地优选级改成9999

[r6]route-policy local permit node 10

[r6-route-policy]if-match ip-prefix 1.1

[r6-route-policy]apply local-preference 9999

[r6-route-policy]quit

[r6]bgp 456

[r6-bgp]peer 5.5.5.5 route-policy local import

[r6-bgp]quit

在R4上查看路由表

display bgp routing-table 1.1.1.1

 BGP local router ID : 4.4.4.4

 Local AS number : 456

 Paths:   2 available, 1 best, 1 select

 BGP routing table entry information of 1.1.1.1/32:

 From: 6.6.6.6 (6.6.6.6)

 Route Duration: 00h01m44s  

 Relay IP Nexthop: 46.1.1.6

 Relay IP Out-Interface: GigabitEthernet0/0/0

 Original nexthop: 5.5.5.5

 Qos information : 0x0

 AS-path 300 100, origin igp, MED 800, localpref 9999, pref-val 0, valid, internal, best, select, active, pre 255, IGP cost 2

 Originator:  5.5.5.5

 Cluster list: 6.6.6.6

 Advertised to such 1 peers:

    24.1.1.2

 BGP routing table entry information of 1.1.1.1/32:

 From: 24.1.1.2 (2.2.2.2)

 Route Duration: 00h33m36s  

 Direct Out-interface: GigabitEthernet0/0/1

 Original nexthop: 24.1.1.2

 Qos information : 0x0

 AS-path 200 100, origin igp, pref-val 0, valid, external, pre 255, not preferred for Local_Pref

 Not advertised to any peer yet

通过以上输出可以看到R6传递过来的路由没有优选是因为Local_Pref

想要华为数通配套实验拓扑和配置笔记的朋友们点赞+关注,评论区留下邮箱发给你!

11)设置路由优选原则第1条: 优选Preferred-Value属性值最大的路由。

查看R6的BGP路由表

[R6]display bgp routing-table

 BGP Local router ID is 6.6.6.6

 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  1.1.1.1/32         5.5.5.5                    9999       0      300 100i

 * i                     4.4.4.4                    100        0      200 100i

通过以上输出可以看到R6去1.1.1.1选择R5,因为R5传递过的路由的本地优先级为9999

在R6上会配置,让R4传递过来的路由的Preferred-Value3000

[R6]route-policy pre permit node 10

[R6-route-policy]if-match ip-prefix 1.1

[R6-route-policy]apply preferred-value 3000

[R6-route-policy]quit

[R6]bgp 456

[R6-bgp]peer 4.4.4.4 route-policy pre import

[R6-bgp]quit

在R6上查看BGP的路由表

[R6]display bgp routing-table

 BGP Local router ID is 6.6.6.6

 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  1.1.1.1/32         4.4.4.4                    100        3000   200 100i

 * i                     5.5.5.5                    9999       0      300 100i

通过以上输出可以看到R6去往1.1.1.1选择了R4,因为它的Preferred-Value为3000

想要华为数通配套实验拓扑和配置笔记的朋友们点赞+关注,评论区留下邮箱发给你!

你可能感兴趣的:(学习,笔记,网络)