实验目的:
1、理解掌握BGP的本地优选属性概念和配置方法。
2、本地优选的属性默认值为100,较高值的路径会被优先选择。
3、本地优先属性,决定离开本自治系统最佳的路径。
实验拓扑:
步骤1:接口IP配置
R1(config)#interface f0/0
R1(config-if)#ip address 12.12.12.1 255.255.255.0
R1(config-if)#no shutdown
R1(config-if)#interface f0/1
R1(config-if)#ip address 14.14.14.1 255.255.255.0
R1(config-if)#no shutdown
R1(config)#interface loopback 0
R1(config-if)#ip address 1.1.1.1 255.255.255.0
R2(config)#interface f0/0
R2(config-if)#ip address 12.12.12.2 255.255.255.0
R2(config-if)#no shutdown
R2(config-if)#interface f0/1
R2(config-if)#ip address 23.23.23.2 255.255.255.0
R2(config-if)#no shutdown
R3(config)#interface f0/1
R3(config-if)#ip address 23.23.23.3 255.255.255.0
R3(config-if)#no shutdown
R3(config-if)#interface f0/0
R3(config-if)#ip address 34.34.34.3 255.255.255.0
R3(config-if)#no shutdown
R4(config)#interface f0/0
R4(config-if)#ip address 34.34.34.4 255.255.255.0
R4(config-if)#no shutdown
R4(config-if)#interface f0/1
R4(config-if)#ip address 14.14.14.4 255.255.255.0
R4(config-if)#no shutdown
步骤2 :bgp协议基本配置
R1(config)#router bgp 12
R1(config-router)#network 12.12.12.0 mask 255.255.255.0
R1(config-router)#network 14.14.14.0 mask 255.255.255.0
R1(config-router)#network 1.1.1.0 mask 255.255.255.0
R1(config-router)#neighbor 12.12.12.2 remote-as 12
R1(config-router)#neighbor 23.23.23.3 remote-as 34
R1(config-router)#neighbor 14.14.14.4 remote-as 34
R2(config)#router bgp 12
R2(config-router)#network 12.12.12.0 mask 255.255.255.0
R2(config-router)#network 23.23.23.0 mask 255.255.255.0
R2(config-router)#neighbor 12.12.12.1 remote-as 12
R2(config-router)#neighbor 23.23.23.3 remote-as 34
R2(config-router)#neighbor 34.34.34.4 remote-as 34
R3(config)#router bgp 34
R3(config-router)#network 23.23.23.0 mask 255.255.255.0
R3(config-router)#network 34.34.34.0 mask 255.255.255.0
R3(config-router)#neighbor 34.34.34.4 remote-as 34
R3(config-router)#neighbor 12.12.12.1 remote-as 12
R3(config-router)#neighbor 23.23.23.2 remote-as 12
R4(config)#router bgp 34
R4(config-router)#network 14.14.14.0 mask 255.255.255.0
R4(config-router)#network 34.34.34.0 mask 255.255.255.0
R4(config-router)#neighbor 34.34.34.3 remote-as 34
R4(config-router)#neighbor 14.14.14.1 remote-as 12
R4(config-router)#neighbor 23.23.23.2 remote-as 12
查看bgp peer关系建立情况:
R1(config-router)#do show ip bgp summary
BGP router identifier 1.1.1.1, local AS number 12
BGP table version is 5, main routing table version 5
4 network entries using 468 bytes of memory
5 path entries using 260 bytes of memory
3/2 BGP path/bestpath attribute entries using 372 bytes of memory
0 BGP route-map cache entries using 0 bytes of memory
0 BGP filter-list cache entries using 0 bytes of memory
BGP using 1100 total bytes of memory
BGP activity 4/0 prefixes, 5/0 paths, scan interval 60 secs
Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
12.12.12.2 4 12 10 10 5 0 0 00:06:41 2
14.14.14.4 4 34 0 0 0 0 0 never Active
23.23.23.3 4 34 0 0 0 0 0 never Active
这是因为bgp的水平分割防环机制。对当前路由器而言,路由更新来自于ibgp peer,就不会发送给其他任何ibgp peer。水平拓扑上ibgp水平分割会导致路由更新不学习。
以23.23.23.0/24网络为例,R2将该路由条目更新发送给R1,R1将其转发给R4学习。对于R1而言,该路由条目更新来自ibgp,则学习,对于R4而言,该路由条目更新来自于ebgp,但该ebgp 属于自身所在as内,故不学习,导致bgp peer-address不可达,peer关系建立失败。
R1(config-router)#router bgp 12
R1(config-router)# neighbor 14.14.14.4 next-hop-self
//将发给对等体的路由下一跳设为自己
R2(config-router)#router bgp 12
R2(config-router)# neighbor 23.23.23.3 next-hop-self
R3(config-router)#router bgp 34
R3(config-router)# neighbor 23.23.23.2 next-hop-self
R4(config-router)#router bgp 34
R4(config-router)# neighbor 14.14.14.1 next-hop-self
此时全网互通
R1#show ip route
Gateway of last resort is not set
34.0.0.0/24 is subnetted, 1 subnets
B 34.34.34.0 [20/0] via 14.14.14.4, 00:09:15
1.0.0.0/24 is subnetted, 1 subnets
C 1.1.1.0 is directly connected, Loopback0
23.0.0.0/24 is subnetted, 1 subnets
B 23.23.23.0 [200/0] via 12.12.12.2, 00:09:15
12.0.0.0/24 is subnetted, 1 subnets
C 12.12.12.0 is directly connected, FastEthernet0/0
14.0.0.0/24 is subnetted, 1 subnets
C 14.14.14.0 is directly connected, FastEthernet0/1
查看R3路由表
R3#show ip route
Gateway of last resort is not set
34.0.0.0/24 is subnetted, 1 subnets
C 34.34.34.0 is directly connected, FastEthernet0/0
1.0.0.0/24 is subnetted, 1 subnets
B 1.1.1.0 [20/0] via 23.23.23.2, 00:10:56
//R3到达1.1.1.0/24网络的下一跳是23.23.23.2
23.0.0.0/24 is subnetted, 1 subnets
C 23.23.23.0 is directly connected, FastEthernet0/1
12.0.0.0/24 is subnetted, 1 subnets
B 12.12.12.0 [20/0] via 23.23.23.2, 00:27:09
14.0.0.0/24 is subnetted, 1 subnets
B 14.14.14.0 [200/0] via 34.34.34.4, 00:29:09
查看R4路由表
R4#show ip route
Gateway of last resort is not set
34.0.0.0/24 is subnetted, 1 subnets
C 34.34.34.0 is directly connected, FastEthernet0/0
1.0.0.0/24 is subnetted, 1 subnets
B 1.1.1.0 [20/0] via 14.14.14.1, 00:12:35
//R4到达1.1.1.0/24的网络下一跳是14.14.14.1
23.0.0.0/24 is subnetted, 1 subnets
B 23.23.23.0 [200/0] via 34.34.34.3, 00:30:37
12.0.0.0/24 is subnetted, 1 subnets
B 12.12.12.0 [20/0] via 14.14.14.1, 00:12:35
14.0.0.0/24 is subnetted, 1 subnets
C 14.14.14.0 is directly connected, FastEthernet0/1
理论上BGP选择的都是最佳路由,但该例中我们通过本地配置“本地优先”来确定数据流如何流出本自治系统。
查看R3的BGP数据库信息表。
R3#show ip bgp
BGP table version is 19, local router ID is 34.34.34.3
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
* i1.1.1.0/24 14.14.14.1 0 100 0 12 i
//100为默认的本地优先属性值。
*> 23.23.23.2 0 12 i
* i12.12.12.0/24 14.14.14.1 0 100 0 12 i
*> 23.23.23.2 0 0 12 i
* 14.14.14.0/24 23.23.23.2 0 12 i
*>i 34.34.34.4 0 100 0 i
* 23.23.23.0/24 23.23.23.2 0 0 12 i
*> 0.0.0.0 0 32768 i
*> 34.34.34.0/24 0.0.0.0 0 32768 i
* i 34.34.34.4 0 100 0 i
查看R4的BGP的数据库信息表:
R4#show ip bgp
BGP table version is 22, local router ID is 34.34.34.4
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
* i1.1.1.0/24 23.23.23.2 0 100 0 12 i
*> 14.14.14.1 0 0 12 i
*> 12.12.12.0/24 14.14.14.1 0 0 12 i
* i 23.23.23.2 0 100 0 12 i
* 14.14.14.0/24 14.14.14.1 0 0 12 i
*> 0.0.0.0 0 32768 i
* 23.23.23.0/24 14.14.14.1 0 12 i
*>i 34.34.34.3 0 100 0 i
* i34.34.34.0/24 34.34.34.3 0 100 0 i
*> 0.0.0.0 0 32768 i
通过对比R3与R4路由器的BGP数据库,只需要调整R4路由器所学习的所有BGP路由的本地优先值。因为BGP会优先选择本地优先属性值较高的路由。
配置R4的路由器,调整本地优先属性值为200:
R4(config)#router bgp 34
R4(config-router)#bgp default local-preference 200
查看R3的BGP数据库:
R3#show ip bgp
BGP table version is 11, local router ID is 34.34.34.3
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
*> 1.1.1.0/24 23.23.23.2 0 12 i
//当对R4的本地优先属性进行调整后,在R3上会发现从R4学习到的路由的本地优先已经改变200。
//同时,也可以看出,此时,R3到达1.1.1.0/24的子网,其下一跳为23.23.23.2,为最佳路由。
*> 12.12.12.0/24 23.23.23.2 0 0 12 i
*> 14.14.14.0/24 23.23.23.2 0 12 i
*> 23.23.23.0/24 0.0.0.0 0 32768 i
* 23.23.23.2 0 0 12 i
*> 34.34.34.0/24 0.0.0.0 0 32768 i
再次查看R3的路由表:
R3#show ip route
Gateway of last resort is not set
34.0.0.0/24 is subnetted, 1 subnets
C 34.34.34.0 is directly connected, FastEthernet0/0
1.0.0.0/24 is subnetted, 1 subnets
B 1.1.1.0 [20/0] via 23.23.23.2, 00:01:01
23.0.0.0/24 is subnetted, 1 subnets
C 23.23.23.0 is directly connected, FastEthernet0/1
12.0.0.0/24 is subnetted, 1 subnets
B 12.12.12.0 [20/0] via 23.23.23.2, 00:01:01
14.0.0.0/24 is subnetted, 1 subnets
B 14.14.14.0 [20/0] via 23.23.23.2, 00:01:01