BGP 有丰富的路由属性. 我们通常控制 BGP 路由属性, 来控制 BGP 路由流向.
cisco 路由器常见路由属性如下:
1. 优先选择最大 weight(权重)的路由 (范围: 0~65535)
2. 优先选择有最大 LOCAL_OREF(本地优先级)的路由 (范围: 0~4294967295)
3. 优先选择从本地路由器始发的路由 (即下一跳 0.0.0.0)
4. 优先选择 AS-path 数量最少的路由
5. 根据 origin 属性, 优先选择具有最低起源类型的路由 (IGP 优先于 EGP 优先于 incomplete)
6. 优先选择具有最小 MED 值的路由 (范围: 0~4294967295)
7.EBGP 优先于 IBGP
8. 优先选择能够通过最近的 IGP 邻居到达的路径 (即对 BGP 下一跳具有最低 IGP 度量值的路径)
9. 如果配置了 maximum-path N(2≤N≤6), 可实现负载均衡 (但 BGP 会继续比较, 只有一条路径被打上 ">" 标签)
10. 如果都是 external(外部的)路由, 优先选择最老 (即最早学到) 的路由
11. 优先选择拥有最小 BGP-router-ID 的路由
12. 如果是从路由反射器 (RR) 学习到的路由, 优先选择拥有最小 cluster-ID(路由反射器的 router-ID)的路由
13. 优先选择具有最低对等体地址接收到的路由(即邻居 IP 地址最小的优先)
实验拓扑图
配置前 R1 上的路由
- R1#sh ip route
- Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
- D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
- N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
- E1 - OSPF external type 1, E2 - OSPF external type 2
- i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
- ia - IS-IS inter area, * - candidate default, U - per-user static route
- o - ODR, P - periodic downloaded static route
- Gateway of last resort is not set
- 172.16.0.0/24 is subnetted, 2 subnets
- C 172.16.12.0 is directly connected, FastEthernet0/0
- C 172.16.13.0 is directly connected, FastEthernet0/1
- 10.0.0.0/32 is subnetted, 2 subnets
- B 10.10.6.6 [20/0] via 172.16.12.2, 00:27:41
- C 10.10.1.1 is directly connected, Loopback0
使用 weight 改变路由
- R1(config-router)#neighbor 172.16.13.3 weight 10
- R1#clear ip bgp * soft
更改 weight 后路由
- R1#sh ip route
- Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
- D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
- N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
- E1 - OSPF external type 1, E2 - OSPF external type 2
- i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
- ia - IS-IS inter area, * - candidate default, U - per-user static route
- o - ODR, P - periodic downloaded static route
- Gateway of last resort is not set
- 172.16.0.0/24 is subnetted, 2 subnets
- C 172.16.12.0 is directly connected, FastEthernet0/0
- C 172.16.13.0 is directly connected, FastEthernet0/1
- 10.0.0.0/32 is subnetted, 2 subnets
- B 10.10.6.6 [20/0] via 172.16.13.3, 00:01:09
- C 10.10.1.1 is directly connected, Loopback0
使用 local-preference 更改路由
更改 R1 配置:
- R1(config)#ip prefix-list mei permit 10.10.6.6/32
- R1(config)#route-map paul permit 10
- R1(config-route-map)#match ip address prefix-list mei
- R1(config-route-map)#set local-preference 200
- R1(config)#route-map paul permit 99
- R1(config-route-map)#router bgp 100
- R1(config-router)#neighbor 172.16.13.3 remote-as 2345
- R1(config-router)#neighbor 172.16.13.3 route-map mei in
- R1(config-router)#do clear ip bgp * so
- 1(config-router)#do sh ip bgp 10.10.6.6/32
- BGP routing table entry for 10.10.6.6/32, version 4
- Paths: (2 available, best #1, table Default-IP-Routing-Table)
- Flag: 0x840
- Advertised to update-groups:
- 1
- 2345 600
- 172.16.13.3 from 172.16.13.3 (10.10.3.3)
Origin IGP, localpref 200, valid, external, best
2345 600
使用 AS-path 更改路由
更改 R1 配置
- R1(config-route-map)#do sh run | s route-map
- route-map paul permit 10
- match ip address prefix-list mei
- set as-path prepend 100 100
- route-map paul permit 99
- R1(config-router)#do sh run | s bgp
- router bgp 100
- no synchronization
- bgp router-id 10.10.1.1
- bgp log-neighbor-changes
- network 10.10.1.1 mask 255.255.255.255
- neighbor 172.16.12.2 remote-as 2345
- neighbor 172.16.12.2 route-map paul in
- neighbor 172.16.13.3 remote-as 2345
- no auto-summary
- R1(config-router)#do clear ip bgp * so
- R1(config-router)#do sh ip bgp 10.10.6.6
- BGP routing table entry for 10.10.6.6/32, version 2
- Paths: (2 available, best #2, table Default-IP-Routing-Table)
- Advertised to update-groups:
- 1
- 100 100 2345 600
- 172.16.12.2 from 172.16.12.2 (10.10.2.2)
Origin IGP, localpref 100, valid, external
- 2345 600
- 172.16.13.3 from 172.16.13.3 (10.10.3.3)
Origin IGP, localpref 100, valid, external, best
使用 MED 更改路由
更改 R1 配置
- R1(config-router)#do sh run | s route-map
- neighbor 172.16.12.2 route-map paul in
- route-map paul permit 10
- match ip address prefix-list mei
- set metric 10000
- route-map paul permit 99
- R1(config-router)#do sh run | s bgp
- router bgp 100
- no synchronization
- bgp router-id 10.10.1.1
- bgp log-neighbor-changes
- network 10.10.1.1 mask 255.255.255.255
- neighbor 172.16.12.2 remote-as 2345
- neighbor 172.16.12.2 route-map paul in
- neighbor 172.16.13.3 remote-as 2345
- no auto-summary
- R1(config-router)#do clear ip bgp * soft
- R1(config-router)#do sh ip bgp 10.10.6.6/32
- BGP routing table entry for 10.10.6.6/32, version 2
- Paths: (2 available, best #1, table Default-IP-Routing-Table)
- Flag: 0x820
- Advertised to update-groups:
- 1
- 2345 600
- 172.16.13.3 from 172.16.13.3 (10.10.3.3)
Origin IGP, localpref 100, valid, external, best
- 2345 600
- 172.16.12.2 from 172.16.12.2 (10.10.2.2)
Origin IGP, metric 10000, localpref 100, valid, external
R1(config-router)#
来源: http://www.bubuko.com/infodetail-3122086.html