实验目的:

l 掌握BGP 13条选路

l 掌握选路应用场景

实验说明:

l 通过此实验练习,可以更好的掌握BGP 13条选路

实验环境:

l 三台支持SPSERVICES的IOS的路由器

l 直通线

实验拓扑:

【CCIE 实验】BGP 13条选路原则实验_基本配置

实验步骤:

R1(config)#interface f0/0

R1(config-if)#ip address 12.1.1.1 255.255.255.0

R1(config-if)#no shutdown

R1(config-if)#int f1/0

R1(config-if)#ip address 13.1.1.1 255.255.255.0

R1(config-if)#no shutdown

R1(config-if)#int lo 0

R1(config-if)#ip address 1.1.1.1 255.255.255.255

R1(config)#router ospf 110

R1(config-router)#router-id 1.1.1.1

R1(config-router)#network 12.1.1.1 0.0.0.0 a 0

R1(config-router)#network 1.1.1.1 0.0.0.0 a 0

R1(config)#router bgp 100

R1(config-router)#bgp router-id 1.1.1.1

R1(config-router)#neighbor 2.2.2.2 remote-as 100

R1(config-router)#neighbor 2.2.2.2 update-source lo 0

R1(config-router)#neighbor 2.2.2.2 next-hop-self

R1(config-router)#neighbor 13.1.1.3 remote-as 200

R2(config)#interface f0/0

R2(config-if)#ip address 12.1.1.2 255.255.255.0

R2(config-if)#no shutdown

R2(config-if)#int f1/1

R2(config-if)#ip address 23.1.1.2 255.255.255.0

R2(config-if)#no shutdown

R2(config)#int lo 0

R2(config-if)#ip address 2.2.2.2 255.255.255.255

R2(config)#router ospf 110

R2(config-router)#router-id 2.2.2.2

R2(config-router)#network 12.1.1.2 0.0.0.0 a 0

R2(config-router)#net

R2(config-router)#network 2.2.2.2 0.0.0.0 a 0

R2(config-router)#

*Sep 28 09:03:58.399: %OSPF-5-ADJCHG: Process 110, Nbr 1.1.1.1 on FastEthernet0/0 from LOADING to FULL, Loading Done

R2(config-router)#

R2(config-router)#

R2(config-router)#

R2(config-router)#

R2(config-router)#exit

R2(config)#router bgp 100

R2(config-router)#bgp ro

R2(config-router)#bgp router-id 2.2.2.2

R2(config-router)#nei

R2(config-router)#neighbor 1.1.1.1 remot

R2(config-router)#neighbor 1.1.1.1 remote-as 100

R2(config-router)#nei

R2(config-router)#neighbor 1.1.1.1 up

R2(config-router)#neighbor 1.1.1.1 update-source lo 0

R2(config-router)#nei

R2(config-router)#neighbor 1.1.1.1 ne

R2(config-router)#neighbor 1.1.1.1 next-hop-s

*Sep 28 09:05:01.299: %BGP-5-ADJCHANGE: neighbor 1.1.1.1 Up

R2(config-router)#neighbor 1.1.1.1 next-hop-s

R2(config-router)#neighbor 1.1.1.1 next-hop-self

R2(config-router)#nei

R2(config-router)#neighbor 23.1.1.3 remot

R2(config-router)#neighbor 23.1.1.3 remote-as 200

R3(config-router)#network 3.3.3.3 mask 255.255.255.255

选路原则1:weight值

没设置weight值前:

R1#show ip bgp

Network Next Hop Metric LocPrf Weight Path

* i3.3.3.3/32 2.2.2.2 0 100 0 200 i

*> 13.1.1.3 0 0 200 i

设置weight值后:

R1(config)#router bgp 100

R1(config-router)#neighbor 2.2.2.2 weight 1

OR

R1(config)#access-list 1 permit 3.3.3.3 0.0.0.0

R1(config)#route-map wei permit 10

R1(config-route-map)#match ip address 1

R1(config-route-map)#set weight 1

R1(config)#route-map wei permit 20

R1(config)#router bgp 100

R1(config-router)#neighbor 2.2.2.2 route-map wei in

验证:

R1#show ip bgp

Network Next Hop Metric LocPrf Weight Path

* >i3.3.3.3/32 2.2.2.2 0 100 1 200 i

* 13.1.1.3 0 0 200 i

选路原则2:第一条选路一致,比较local-preference

使用原则:

1, 只能在IBGP传递,不能在EBGP传递

2, 告诉本路由器或IBGP邻居如何离开本AS

3, 默认local-preference为100,越大越好

没有设置local-preference前:

R1#show ip bgp

Network Next Hop Metric LocPrf Weight Path

* i3.3.3.3/32 2.2.2.2 0 100 0 200 i

*> 13.1.1.3 0 0 200 i

设置local-preference后:

R1(config)#router bgp 100

R1(config-router)#bgp default local-preference 101

OR

R2(config)#access-list 1 permit 3.3.3.3 0.0.0.0

R2(config)#route-map loc permit 10

R2(config-route-map)#match ip address 1

R2(config-route-map)#set local-preference 101

R2(config)#route-map loc permit 20

R2(config)#router bgp 100

R2(config-router)#neighbor 1.1.1.1 route-map loc out

选路原则3:前两条选路一致,比较起源本地

本地起源意味着该路由通过本地路由器起源,

起源的方式:network,redistribution ,agg

当路由器本地起源的路由同时通过其他邻居收到此路由

优先选择本地起源的路由

R3#show ip bgp 3.3.3.3

BGP routing table entry for 3.3.3.3/32, version 2

Paths: (1 available, best #1, table Default-IP-Routing-Table)

Advertised to update-groups:

1

Local

0.0.0.0 from 0.0.0.0 (3.3.3.3)

Origin IGP, metric 0, localpref 100, weight 32768, valid, sourced, local, best

选路原则4:前三条选路一致,比较AS-path

AS-path原则:

优选最短的AS-path

对EBGP邻居起作用

环境设定:R1和R2同时有条路由100.100.100.100/32发送给R3

R1/R2(config)#int lo 100

R1/R2(config-if)#ip address 100.100.100.100 255.255.255.255

R1/R2(config-router)#network 100.100.100.100 mask 255.255.255.255

此时:

R3#show ip bgp

Network Next Hop Metric LocPrf Weight Path

* 100.100.100.100/32

23.1.1.2 0 0 100 i

*> 13.1.1.1 0 0 100 i

设置AS-path选路原则:当As-path经历的AS数约小越优先

R2(config)#access-list 2 permit 100.100.100.100 0.0.0.0

R2(config)#route-map as-path permit 10

R2(config-route-map)#match ip address 2

R2(config-route-map)#set as-path prepend 300 400

R2(config)#route-map as-path permit 20

R2(config)#router bgp 100

R2(config-router)#neighbor 23.1.1.3 route-map as-path out

R3(config)#access-list 1 permit 100.100.100.100 0.0.0.0

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

R3(config-route-map)#match ip address 1

R3(config-route-map)#set as-path prepend last-as 3

R3(config)#route-map as-path permit 20

R3(config)#router bgp 200

R3(config-router)#neighbor 13.1.1.1 route-map as-path in

验证:

R3#show ip bgp 100.100.100.100

BGP routing table entry for 100.100.100.100/32, version 8

Paths: (2 available, best #1, table Default-IP-Routing-Table)

Flag: 0x820

Advertised to update-groups:

1

100 300 400

23.1.1.2 from 23.1.1.2 (2.2.2.2)

Origin IGP, metric 0, localpref 100, valid, external, best

100 100 100 100

13.1.1.1 from 13.1.1.1 (1.1.1.1)

Origin IGP, metric 0, localpref 100, valid, external

注:

通过bgp bestpath as-path ignore忽略该规则的选举

选路原则5:前四条选路一致,比较Origin

比较原则:i>e>?

例如:

R3#show ip bgp

Network Next Hop Metric LocPrf Weight Path

*> 3.3.3.3/32 0.0.0.0 0 32768 i

100 100 100 100 i

*> 200.200.200.200/32

33.33.33.34 0 32768 ?

选路原则6:前五条选路一致,比较MED

MED规则:

告诉EBGP邻居怎么进入本AS或告诉自己以及IBGP邻居如何离开本AS

从EBGP学习到BGP条目携带的MED只可以传给其他IBGP

从IBGP或下一个EBGP学习到BGP路由条目的MED为0或者其他值,缺省不会传给EBGP邻居,显示为空。

汇总方式生成的BGP条目,MED值为空

实验拓扑:

【CCIE 实验】BGP 13条选路原则实验_BGP_02

实验步骤(基于之前的配置)

R3(config)#router bgp 200

R3(config-router)#neighbor 34.1.1.4 remote-as 300

R4(config)#router bgp 300

R4(config-router)#bgp router-id 4.4.4.4

R4(config-router)#neighbor 34.1.1.3 remote-as 200

修改MED值:

R2(config)#route-map med permit 10

R2(config-route-map)#match ip address 2

R2(config-route-map)#set metric 200

R2(config)#route-map med permit 20

R2(config)#router bgp 100

R2(config-router)#neighbor 23.1.1.3 route-map med out

R3(config)#route-map med permit 10

R3(config-route-map)#match ip address 1

R3(config-route-map)#set metric 100

R3(config)#route-map med permit 20

R3(config-router)#neighbor 13.1.1.1 route-map med in

验证:

R3#show ip bgp 100.100.100.100

BGP routing table entry for 100.100.100.100/32, version 12

Paths: (2 available, best #2, table Default-IP-Routing-Table)

Flag: 0x10840

Advertised to update-groups:

1

100

23.1.1.2 from 23.1.1.2 (2.2.2.2)

Origin IGP, metric 200, localpref 100, valid, external

100

13.1.1.1 from 13.1.1.1 (1.1.1.1)

Origin IGP, metric 100, localpref 100, valid, external, best

R4#show ip bgp 100.100.100.100

BGP routing table entry for 100.100.100.100/32, version 5

Paths: (1 available, best #1, table Default-IP-Routing-Table)

Not advertised to any peer

200 100

34.1.1.3 from 34.1.1.3 (3.3.3.3)

Origin IGP, localpref 100, valid, external, best

通过Bgp bestpath med missing-med-worst来显示隐藏的med值

R4(config)#router bgp 300

R4(config-router)#bgp bestpath med missing-as-worst

R4#show ip bgp 100.100.100.100

*Sep 28 10:57:59.611: %SYS-5-CONFIG_I: Configured from console by console

R4#show ip bgp 100.100.100.100

BGP routing table entry for 100.100.100.100/32, version 5

Paths: (1 available, best #1, table Default-IP-Routing-Table)

Not advertised to any peer

200 100

34.1.1.3 from 34.1.1.3 (3.3.3.3)

Origin IGP, metric 4294967295, localpref 100, valid, external, best

注:med比较条件:第一个AS号相同才比较med这个选路原则

通过bgp always-compare-med打破AS相同的限制

R4(config)#router bgp 300

R4(config-router)#bgp always-compare-med

选路原则7:前六条选路一致,比较EBGP邻居优于IBGP邻居学来的路由

R1#show ip bgp

Network Next Hop Metric LocPrf Weight Path

* i3.3.3.3/32 2.2.2.2 0 100 0 200 i

*> 13.1.1.3 0 0 200 i

选路原则8:前七条选路一致,比较最近的IGP邻居

实验拓扑:

【CCIE 实验】BGP 13条选路原则实验_BGP_03

实验步骤(基本配置同上,略):

R3(config-if)#router bgp 200

R3(config-router)#network 3.3.3.3 mask 255.255.255.255

验证:

R4#show ip bgp 3.3.3.3

BGP routing table entry for 3.3.3.3/32, version 3

Paths: (2 available, best #1, table Default-IP-Routing-Table)

Flag: 0x820

Not advertised to any peer

200

1.1.1.1 (metric 2) from 1.1.1.1 (1.1.1.1)

Origin IGP, metric 0, localpref 100, valid, internal, best

200

2.2.2.2 (metric 2) from 2.2.2.2 (2.2.2.2)

Origin IGP, metric 0, localpref 100, valid, internal

修改从1.1.1.1学到的IGP开销变大

R1(config-router)#int lo 0

R1(config-if)#ip ospf cost 100

R4#show ip bgp 3.3.3.3

BGP routing table entry for 3.3.3.3/32, version 4

Paths: (2 available, best #2, table Default-IP-Routing-Table)

Flag: 0x800

Not advertised to any peer

200

1.1.1.1 (metric 101) from 1.1.1.1 (1.1.1.1)

Origin IGP, metric 0, localpref 100, valid, internal

200

2.2.2.2 (metric 2) from 2.2.2.2 (2.2.2.2)

Origin IGP, metric 0, localpref 100, valid, internal, best

选路原则9:前八条选路一致,EBGP等价负载均衡

注:默认情况下第八条比不出来的时候,直接跳过第九条,默认第九条关闭,当开启时候,通过第九条能实现ebgp的等价负载均衡

R4(config)#router bgp 100

R4(config-router)#network 4.4.4.4 mask 255.255.255.255

此时:

R3#show ip bgp 4.4.4.4

BGP routing table entry for 4.4.4.4/32, version 3

Paths: (2 available, best #2, table Default-IP-Routing-Table)

Flag: 0x820

Advertised to update-groups:

2

100

13.1.1.1 from 13.1.1.1 (1.1.1.1)

Origin IGP, localpref 100, valid, external

100

23.1.1.2 from 23.1.1.2 (2.2.2.2)

Origin IGP, localpref 100, valid, external, best

R3#show ip route bgp

4.0.0.0/32 is subnetted, 1 subnets

B 4.4.4.4 [20/0] via 23.1.1.2, 00:01:20

开启负载功能

R3(config)#router bgp 200

R3(config-router)#maximum-paths 2

此时:

R3#show ip bgp 4.4.4.4

BGP routing table entry for 4.4.4.4/32, version 4

Paths: (2 available, best #2, table Default-IP-Routing-Table)

Multipath: eBGP

Advertised to update-groups:

2

100

13.1.1.1 from 13.1.1.1 (1.1.1.1)

Origin IGP, localpref 100, valid, external, multipath

100

23.1.1.2 from 23.1.1.2 (2.2.2.2)

Origin IGP, localpref 100, valid, external, multipath, best

R3#show ip route bgp

4.0.0.0/32 is subnetted, 1 subnets

B 4.4.4.4 [20/0] via 23.1.1.2, 00:03:49

[20/0] via 13.1.1.1, 00:02:03

选路原则10:前九条选路一致,选择最老的EBGP邻居

R3#show ip bgp 4.4.4.4

BGP routing table entry for 4.4.4.4/32, version 5

Paths: (2 available, best #2, table Default-IP-Routing-Table)

Flag: 0x800

Advertised to update-groups:

2

100

13.1.1.1 from 13.1.1.1 (1.1.1.1)

Origin IGP, localpref 100, valid, external

100

23.1.1.2 from 23.1.1.2 (2.2.2.2)

Origin IGP, localpref 100, valid, external, best

验证:

是23.1.1.2从新建立ebgp邻居关系

R2#clear ip bgp *

R3#show ip bgp summary

Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd

13.1.1.1 4 100 22 26 6 0 0 00:16:53 1

23.1.1.2 4 100 23 28 0 0 0 00:00:23 0

R3#show ip bgp 4.4.4.4

BGP routing table entry for 4.4.4.4/32, version 6

Paths: (2 available, best #2, table Default-IP-Routing-Table)

Flag: 0x840

Advertised to update-groups:

2

100

23.1.1.2 from 23.1.1.2 (2.2.2.2)

Origin IGP, localpref 100, valid, external

100

13.1.1.1 from 13.1.1.1 (1.1.1.1)

Origin IGP, localpref 100, valid, external, best

注:打上bgp bestpath compare-routerid忽略第十条

选路原则11:前十条选路一致,最低的EBGP/IBGP router-id

验证:

打上bgp bestpath compare-routerid忽略第十条验证EBGP router-id

R3#show ip bgp 4.4.4.4

BGP routing table entry for 4.4.4.4/32, version 6

Paths: (2 available, best #2, table Default-IP-Routing-Table)

Advertised to update-groups:

2

100

23.1.1.2 from 23.1.1.2 (2.2.2.2)

Origin IGP, localpref 100, valid, external

100

13.1.1.1 from 13.1.1.1 (1.1.1.1)

Origin IGP, localpref 100, valid, external, best

验证IBGP router-id

R4#show ip bgp 3.3.3.3

BGP routing table entry for 3.3.3.3/32, version 8

Paths: (2 available, best #2, table Default-IP-Routing-Table)

Flag: 0x800

Not advertised to any peer

200

2.2.2.2 (metric 2) from 2.2.2.2 (2.2.2.2)

Origin IGP, metric 0, localpref 100, valid, internal

200

1.1.1.1 (metric 2) from 1.1.1.1 (1.1.1.1)

Origin IGP, metric 0, localpref 100, valid, internal, best

选路原则12:前十一条选路一致,针对于IBGP Cluster_list短的优先

实验拓扑:

【CCIE 实验】BGP 13条选路原则实验_CCIE_04

实验步骤:

R1(config)#interface f0/0

R1(config-if)#ip address 12.1.1.1 255.255.255.0

R1(config-if)#no shutdown

R1(config-if)#int lo 0

R1(config-if)#ip address 1.1.1.1 255.255.255.255

R1(config-if)#int lo 100

R1(config-if)#ip address 100.100.100.100 255.255.255.255

R1(config)#router ospf 110

R1(config-router)#network 1.1.1.1 0.0.0.0 a 0

R1(config-router)#network 12.1.1.1 0.0.0.0 a 0

R1(config)#router bgp 100

R1(config-router)#neighbor 2.2.2.2 remote-as 100

R1(config-router)#neighbor 2.2.2.2 update-source lo 0

R1(config-router)#neighbor 2.2.2.2 next-hop-self

R1(config-router)#network 100.100.100.100 mask 255.255.255.255

R2(config)#interface f0/0

R2(config-if)#ip address 12.1.1.2 255.255.255.0

R2(config-if)#no shutdown

R2(config-if)#int f1/1

R2(config-if)#ip address 23.1.1.2 255.255.255.0

R2(config-if)#no shutdown

R2(config-if)#int f1/0

R2(config-if)#ip address 24.1.1.2 255.255.255.0

R2(config-if)#no shutdown

R2(config-if)#int lo 0

R2(config-if)#ip address 2.2.2.2 255.255.255.255

R2(config)#router ospf 110

R2(config-router)#router-id 2.2.2.2

R2(config-router)#network 12.1.1.2 0.0.0.0 a 0

R2(config-router)#network 23.1.1.2 0.0.0.0 a 0

R2(config-router)#network 24.1.1.2 0.0.0.0 a 0

R2(config-router)#network 2.2.2.2 0.0.0.0 a 0

R2(config)#router bgp 100

R2(config-router)#bgp router-id 2.2.2.2

R2(config-router)#neighbor 1.1.1.1 remote-as 100

R2(config-router)#neighbor 1.1.1.1 update-source lo 0

R2(config-router)#neighbor 1.1.1.1 route-reflector-client

R2(config-router)#neighbor 4.4.4.4 remote-as 100

R2(config-router)#neighbor 4.4.4.4 update-source lo 0

R2(config-router)#neighbor 4.4.4.4 route-reflector-client

R2(config-router)#neighbor 3.3.3.3 remote-as 100

R2(config-router)#neighbor 3.3.3.3 update-source lo 0

R2(config-router)#neighbor 3.3.3.3 route-reflector-client

R3(config)#interface f1/1

R3(config-if)#ip address 23.1.1.3 255.255.255.0

R3(config-if)#no shutdown

R3(config-if)#int f0/0

R3(config-if)#ip address 34.1.1.3 255.255.255.0

R3(config-if)#no shutdown

R3(config-if)#int lo 0

R3(config-if)#ip address 3.3.3.3 255.255.255.255

R3(config)#router ospf 110

R3(config-router)#router-id 3.3.3.3

R3(config-router)#network 23.1.1.3 0.0.0.0 a 0

R3(config-router)#network 34.1.1.3 0.0.0.0 a 0

R3(config-router)#network 3.3.3.3 0.0.0.0 a 0

R3(config)#router bgp 100

R3(config-router)#bgp router-id 3.3.3.3

R3(config-router)#neighbor 2.2.2.2 remote-as 100

R3(config-router)#neighbor 2.2.2.2 update-source lo 0

R3(config-router)#neighbor 4.4.4.4 remote-as 100

R3(config-router)#neighbor 4.4.4.4 update-source lo 0

R3(config-router)#neighbor 4.4.4.4 route-reflector-client

R4(config)#interface f0/0

R4(config-if)#ip address 34.1.1.4 255.255.255.0

R4(config-if)#no shutdown

R4(config-if)#int f1/0

R4(config-if)#ip address 24.1.1.4 255.255.255.0

R4(config-if)#no shutdown

R4(config-if)#int lo 0

R4(config-if)#ip address 4.4.4.4 255.255.255.255

R4(config)#router ospf 110

R4(config-router)#router-id 4.4.4.4

R4(config-router)#network 34.1.1.4 0.0.0.0 a 0

R4(config-router)#network 24.1.1.4 0.0.0.0 a 0

R4(config-router)#network 4.4.4.4 0.0.0.0 a 0

R4(config)#router bgp 100

R4(config-router)#bgp router-id 4.4.4.4

R4(config-router)#neighbor 3.3.3.3 remot

R4(config-router)#neighbor 3.3.3.3 remote-as 100

R4(config-router)#neighbor 3.3.3.3 update-source lo 0

R4(config-router)#neighbor 2.2.2.2 remote-as 100

R4(config-router)#neighbor 2.2.2.2 update-source lo 0

验证:

R4#show ip bgp 100.100.100.100

BGP routing table entry for 100.100.100.100/32, version 2

Paths: (2 available, best #2, table Default-IP-Routing-Table)

Flag: 0x820

Not advertised to any peer

Local

1.1.1.1 (metric 3) from 3.3.3.3 (3.3.3.3)

Origin IGP, metric 0, localpref 100, valid, internal

Originator: 100.100.100.100, Cluster list: 3.3.3.3, 2.2.2.2

Local

1.1.1.1 (metric 3) from 2.2.2.2 (2.2.2.2)

Origin IGP, metric 0, localpref 100, valid, internal, best

Originator: 100.100.100.100, Cluster list: 2.2.2.2

选路原则13:前十二条选路一致,最低的邻居地址的路径

实验拓扑:

【CCIE 实验】BGP 13条选路原则实验_基本配置_05

实验步骤(略)

验证:

R4#show ip bgp 100.100.100.100

BGP routing table entry for 100.100.100.100/32, version 2

Paths: (2 available, best #2, table Default-IP-Routing-Table)

Not advertised to any peer

Local

1.1.1.1 (metric 3) from 3.3.3.3 (3.3.3.3)

Origin IGP, metric 0, localpref 100, valid, internal

Originator: 100.100.100.100, Cluster list: 3.3.3.3

Local

1.1.1.1 (metric 3) from 2.2.2.2 (2.2.2.2)

Origin IGP, metric 0, localpref 100, valid, internal, best

Originator: 100.100.100.100, Cluster list: 2.2.2.2