1、掌握基于 route-map 的本地优先配置方法。
2、使用 route-map 配置可以定置基于目标网络的本地优先。
网络图:
配置好各路由器的IP地址等基本信息,测试互连可达。
配置好各路由器的BGP协议。
查看R3和R4的路由表:
R3#show ip route
Gateway of last resort is not set
172.16.0.0/24 is subnetted, 1 subnets
B 172.16.1.0 [20/0] via 192.168.1.1, 00:00:52
10.0.0.0/24 is subnetted, 1 subnets
C 10.1.1.0 is directly connected, Serial0/1
130.130.0.0/24 is subnetted, 1 subnets
B 130.130.1.0 [20/0] via 192.168.1.1, 00:01:23 ---->下一跳是192.168.1.1
C 192.168.1.0/24 is directly connected, Serial0/0
B 192.168.2.0/24 [200/0] via 10.1.1.2, 00:02:00
150.150.0.0/24 is subnetted, 1 subnets
B 150.150.1.0 [20/0] via 192.168.1.1, 00:00:22 ---->下一跳是192.168.1.1
R4#show ip route
Gateway of last resort is not set
172.16.0.0/24 is subnetted, 1 subnets
B 172.16.1.0 [20/0] via 192.168.2.2, 00:02:29
10.0.0.0/24 is subnetted, 1 subnets
C 10.1.1.0 is directly connected, Serial0/1
130.130.0.0/24 is subnetted, 1 subnets
B 130.130.1.0 [20/0] via 192.168.2.2, 00:01:58 ---->下一跳是192.168.2.2
B 192.168.1.0/24 [200/0] via 10.1.1.1, 00:01:05
C 192.168.2.0/24 is directly connected, Serial0/0
150.150.0.0/24 is subnetted, 1 subnets
B 150.150.1.0 [20/0] via 192.168.2.2, 00:00:57 ---->下一跳是192.168.2.2
这里假设R1和R4之间的链路是100Mbps的以太网,其它的都是2Mbps的串行链路,得出下表信息:
(S:Serial F:FastEthernet Lo:Loopback)
R3---(S)--->R2---(Lo)--->150.150.1.0/24
R3---(S)--->R2---(S)---->R1---(Lo)--->130.130.1.0/24
R3---(S)--->R4---(F)---->R1---(Lo)--->130.130.1.0/24
R4---(F)--->R1---(Lo)--->130.130.1.0/24
R4---(F)--->R1---(S)---->R2---(Lo)--->150.150.1.0/24
R4---(S)--->R3---(S)---->R2---(Lo)--->150.150.1.0/24
按以上表可以看出,R3到130.130.1.0/24的最佳路径是:
R3---(S)--->R4---(F)---->R1---(Lo)--->130.130.1.0/24
为了配置BGP协议能够选择预定的最佳路径以到达130.130.1.0/24,可以使用本地优先属性,但是如果仅仅是简单地配置在R3的本地优先级为100,在R4上配置本地优先级为200,那又会产生另外一问题,即如果R3要到达150.150.1.0/24网络,会经过的路径是:
R3---(S)--->R4---(F)---->R1---(S)--->R2---(Lo)--->150.150.1.0/24
明显不合理,数据在拓扑中绕了一大圈。
产生此问题的主要原因是:本地优先属性会影响数据流如何流出本地自治系统。
解决的方法是:使用基于router-map的策略配置,针对不同的目标进行路由调整。
首先查看R3和R4的BGP路由数据库:
R3#show ip bgp
BGP table version is 12, local router ID is 192.168.1.2
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
*> 10.1.1.0/24 0.0.0.0 0 32768 i
* i 10.1.1.2 0 100 0 i
* i130.130.1.0/24 192.168.2.2 0 100 0 64512 i
*> 192.168.1.1 0 64512 i
* i150.150.1.0/24 192.168.2.2 0 100 0 64512 i
*> 192.168.1.1 0 0 64512 i
* i172.16.1.0/24 192.168.2.2 0 100 0 64512 i
*> 192.168.1.1 0 0 64512 i
*> 192.168.1.0 0.0.0.0 0 32768 i
* 192.168.1.1 0 0 64512 i
* 192.168.2.0 192.168.1.1 0 64512 i
*>i 10.1.1.2 0 100 0 i
R4#show ip bgp
BGP table version is 8, local router ID is 192.168.2.1
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
* i10.1.1.0/24 10.1.1.1 0 100 0 i
*> 0.0.0.0 0 32768 i
* i130.130.1.0/24 192.168.1.1 0 100 0 64512 i
*> 192.168.2.2 0 0 64512 i
* i150.150.1.0/24 192.168.1.1 0 100 0 64512 i
*> 192.168.2.2 0 64512 i
* i172.16.1.0/24 192.168.1.1 0 100 0 64512 i
*> 192.168.2.2 0 0 64512 i
* 192.168.1.0 192.168.2.2 0 64512 i
*>i 10.1.1.1 0 100 0 i
* 192.168.2.0 192.168.2.2 0 0 64512 i
*> 0.0.0.0 0 32768 i
R3路由器的BGP没有选择192.168.2.2/24的原因是因为BGP的选路规则之一:
EBGP对等体通告的路由优于IBGP对等体通行的路由。(外部优于内部)
由于BGP的本地优先属性默认为100,所以在R4上只需要针对130.130.1.0/24的网络调整其本地优先属性大于100即可。
配置如下:
R4(config)#access 1 permit 130.130.1.0 0.0.0.255 ---->划定作用范围
R4(config)#route-map set-local-preference permit 10
R4(config-route-map)#match ip add 1 ----->对指定的范围操作
R4(config-route-map)#set local-preference 200 ---->设置本地优先属性值为200
R4(config-route-map)#exit
R4(config)#route-map set-local-preference per 20 ---->啥都不写默认通过全部,使用默认值
R4(config-route-map)#exit
R4(config)#router bgp 64513
R4(config-router)#neighbor 192.168.2.2 route-map set-local-preference in ---->针对此邻居发送的路由操作,方向是in
R4(config-router)#exit
R4(config)#end
R4#clear ip bgp * soft in
完成后查看R4的BGP数据库:
R4#show ip bgp
BGP table version is 8, local router ID is 192.168.2.1
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
* i10.1.1.0/24 10.1.1.1 0 100 0 i
*> 0.0.0.0 0 32768 i
*> 130.130.1.0/24 192.168.2.2 0 200 0 64512 i ---->目标条目的LocPrf值已经变为200
*> 150.150.1.0/24 192.168.2.2 0 64512 i
* i 192.168.1.1 0 100 0 64512 i
*> 172.16.1.0/24 192.168.2.2 0 0 64512 i
* i 192.168.1.1 0 100 0 64512 i
* 192.168.1.0 192.168.2.2 0 64512 i
*>i 10.1.1.1 0 100 0 i
* 192.168.2.0 192.168.2.2 0 0 64512 i
*> 0.0.0.0 0 32768 i
查看R3的BGP数据库:
R3#show ip bgp
BGP table version is 9, local router ID is 192.168.1.2
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
* i10.1.1.0/24 10.1.1.2 0 100 0 i
*> 0.0.0.0 0 32768 i
* 130.130.1.0/24 192.168.1.1 0 64512 i
*>i 192.168.2.2 0 200 0 64512 i
----->也变成了200,最前面的“>”指出这是最佳路由
* i150.150.1.0/24 192.168.2.2 0 100 0 64512 i
*> 192.168.1.1 0 0 64512 i
* i172.16.1.0/24 192.168.2.2 0 100 0 64512 i
*> 192.168.1.1 0 0 64512 i
* 192.168.1.0 192.168.1.1 0 0 64512 i
*> 0.0.0.0 0 32768 i
* 192.168.2.0 192.168.1.1 0 64512 i
*>i 10.1.1.2 0 100 0 i
为了确切地判断出R3到达130.130.1.0/24网络使用的是最佳路由,在R4上配置下一跳属性指向自己:
R4(config)#router bgp 64513
R4(config-router)#neighbor 10.1.1.1 next-hop-self ----->指向自己
R4(config-router)#exit
再查看R3的BGP数据库:
R3#show ip bgp
BGP table version is 10, local router ID is 192.168.1.2
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
* i10.1.1.0/24 10.1.1.2 0 100 0 i
*> 0.0.0.0 0 32768 i
* 130.130.1.0/24 192.168.1.1 0 64512 i
*>i 10.1.1.2 0 200 0 64512 i
----->指向了10.1.1.2
* i150.150.1.0/24 10.1.1.2 0 100 0 64512 i
*> 192.168.1.1 0 0 64512 i
* i172.16.1.0/24 10.1.1.2 0 100 0 64512 i
*> 192.168.1.1 0 0 64512 i
* 192.168.1.0 192.168.1.1 0 0 64512 i
*> 0.0.0.0 0 32768 i
* 192.168.2.0 192.168.1.1 0 64512 i
*>i 10.1.1.2 0 100 0 i
查看R3和R4的路由表:
R3#show ip route
Gateway of last resort is not set
172.16.0.0/24 is subnetted, 1 subnets
B 172.16.1.0 [20/0] via 192.168.1.1, 00:18:45
10.0.0.0/24 is subnetted, 1 subnets
C 10.1.1.0 is directly connected, Serial0/1
130.130.0.0/24 is subnetted, 1 subnets
B 130.130.1.0 [200/0] via 10.1.1.2, 00:02:37
C 192.168.1.0/24 is directly connected, Serial0/0
B 192.168.2.0/24 [200/0] via 10.1.1.2, 00:18:41
150.150.0.0/24 is subnetted, 1 subnets
B 150.150.1.0 [20/0] via 192.168.1.1, 00:18:45
R4#show ip route
Gateway of last resort is not set
172.16.0.0/24 is subnetted, 1 subnets
B 172.16.1.0 [20/0] via 192.168.2.2, 00:22:08
10.0.0.0/24 is subnetted, 1 subnets
C 10.1.1.0 is directly connected, Serial0/1
130.130.0.0/24 is subnetted, 1 subnets
B 130.130.1.0 [20/0] via 192.168.2.2, 00:18:10
B 192.168.1.0/24 [200/0] via 10.1.1.1, 00:22:08
C 192.168.2.0/24 is directly connected, Serial0/0
150.150.0.0/24 is subnetted, 1 subnets
B 150.150.1.0 [20/0] via 192.168.2.2, 00:22:08
通过查看R3和R4的路由表,可以看出本地优先值仅仅影响了64513区域的所有路由器如何到达130.130.1.0/24网络,没有影响其它目标网络。
跟踪数据路径:
R3#tracer 130.130.1.1
Type escape sequence to abort.
Tracing the route to 130.130.1.1
1 10.1.1.2 44 msec 60 msec 16 msec
2 192.168.2.2 56 msec * 48 msec
R3#tracer 150.150.1.1
Type escape sequence to abort.
Tracing the route to 150.150.1.1
1 192.168.1.1 52 msec * 40 msec
数据已经按目的路径通过。