实验目的:
1、掌握基于route-map的本地优先配置方法。
2、使用route-map配置可以定置基于目标网络的本地优先。
实验拓扑:
接口IP配置及bgp基础配置详见
CSDNhttps://mp.csdn.net/mp_blog/creation/editor?spm=1001.2014.3001.5352
查看R3与R4的路由表:
R3#show ip route Gateway of last resort is not set34.0.0.0/24 is subnetted, 1 subnets
C 34.34.34.0 is directly connected, FastEthernet0/01.0.0.0/24 is subnetted, 1 subnets
B 1.1.1.0 [20/0] via 23.23.23.2, 01:58:36
//到达1.1.1.0/24网络的下一跳是23.23.23.22.0.0.0/24 is subnetted, 1 subnets
B 2.2.2.0 [20/0] via 23.23.23.2, 00:03:4223.0.0.0/24 is subnetted, 1 subnets
//到达2.2.2.0/24网络的下一跳是23.23.23.2
C 23.23.23.0 is directly connected, FastEthernet0/112.0.0.0/24 is subnetted, 1 subnets
B 12.12.12.0 [20/0] via 23.23.23.2, 01:58:3614.0.0.0/24 is subnetted, 1 subnets
B 14.14.14.0 [20/0] via 23.23.23.2, 00:00:27R4#sh ip route Gateway of last resort is not set34.0.0.0/24 is subnetted, 1 subnets
C 34.34.34.0 is directly connected, FastEthernet0/01.0.0.0/24 is subnetted, 1 subnets
B 1.1.1.0 [20/0] via 14.14.14.1, 00:00:06
//到达1.1.1.0/24网络的下一跳为14.14.14.12.0.0.0/24 is subnetted, 1 subnets
B 2.2.2.0 [20/0] via 14.14.14.1, 00:00:06
//到达2.2.2.0/24网络的下一跳为14.14.14.123.0.0.0/24 is subnetted, 1 subnets
B 23.23.23.0 [200/0] via 34.34.34.3, 00:00:0612.0.0.0/24 is subnetted, 1 subnets
B 12.12.12.0 [20/0] via 14.14.14.1, 00:00:0614.0.0.0/24 is subnetted, 1 subnets
C 14.14.14.0 is directly connected, FastEthernet0/1
对R3与R4的路由表进行分析结果如下:
R3 ————> R2————> 2.2.2.0/24
R3 ————> R2————> R1————> 2.2.2.0/24
R4 ————> R1————> 2.2.2.0/24
R4 ————> R1————> R2————> 2.2.2.0/24
通过上述分析及结合拓扑,可以得出R3到达1.1.1.0/24的网络最佳路由为:
R3 ————> R4 ————> R1————> 2.2.2.0/24
为了配置BGP协议能够为R3选择最佳路由到达2.2.2.0/24的网络,可以使用本地优先属性。但是如果仅仅简单的配置在R3的本地优先为100,R4的本地优先为200,那么又会产生另外一个问题,即R3如果需要到达2.2.2.0/24的网络,会选择如下路由:
R3 ————> R4————> R1————> R2 ————> 2.2.2.0/24
产生此问题的主要原因是:本地优先会影响数据流如何流出本地自治系统。
解决问题的方法是:使用基于route-map的策略配置,针对不同的目标进行路由调整。
首先查看R3和R4路由器的数据库:
R3#show ip bgp
………………………………Network Next Hop Metric LocPrf Weight Path
* i1.1.1.0/24 14.14.14.1 0 100 0 12 i
*> 23.23.23.2 0 12 i
* i2.2.2.0/24 14.14.14.1 0 100 0 12 i
*> 23.23.23.2 0 0 12 i
………………………………
*> 0.0.0.0 0 32768 i
R3路由器的BGP协议没有选择14.14.14.0/24的原因是因为BGP的选路规则:EBGP对等体通告的路由优于IBGP对等体通告的路由。
R4#show ip bgp
…………………………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
* i2.2.2.0/24 23.23.23.2 0 100 0 12 i
*> 14.14.14.1 0 12 i
…………………………
由于BGP的本地优先默认值为100,所以在R4上只需要将针对1.1.1.0/24网络路由的本地优先调整大于100即可,其配置如下:
R4(config)#access-list 1 permit 1.1.1.0 0.0.0.255
//使用ACL匹配需要修改本地优先的路由。
R4(config)#route-map set_lp permit 10
R4(config-route-map)#match ip address 1
//对ACL 1所指出的路由进行匹配
R4(config-route-map)#set local-preference 200
//对匹配ACL 1所指出的路由,修改其本地优先值为200
//此值将会影响本地自治系统的其它路由器,如何到达1.1.1.0/24的网络。
R4(config)#route-map set_lp permit 20
//配置空的路由图,保证其它路由均按默认方式进行通告。
R4(config)#router bgp 34
R4(config-router)#neighbor 14.14.14.1 route-map set_lp in
//针对192.168.2.2的对等体发送的路由进行操作。其方向是in的方向。
在R4上查看BGP的数据库
R4#show ip bgp
BGP table version is 1, 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, ? - incompleteNetwork 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 200 0 12 i
//R4上显示相应的路由的本地优先已经为200。
* i2.2.2.0/24 23.23.23.2 0 100 0 12 i
……………………
查看R3的BGP的数据库
R3#show ip bgp
BGP table version is 23, 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, ? - incompleteNetwork Next Hop Metric LocPrf Weight Path
*>i1.1.1.0/24 14.14.14.1 0 200 0 12 i
* 23.23.23.2 0 12 i
//此时,在R3上查看到达目标网络的路由的本地优先为200,其下一跳为14.14.14.1
* i2.2.2.0/24 14.14.14.1 0 100 0 12 i
*> 23.23.23.2 0 0 12 i
………………………………
为了确切的判断出R3到达1.1.1.0/24的网络路由,使用的是最佳路由,在R4路由器上配置下一跳属性:
R4(config)#router bgp 34
R4(config-router)#neighbor 34.34.34.3 next-hop-self
查看R3和R4的路由表,可以看出本地优先仅仅影响了34自治系统的所有路由器如何到达1.1.1.0/24的网络,没有影响到其它的目标路由。
R3#show ip route Gateway of last resort is not set34.0.0.0/24 is subnetted, 1 subnets
C 34.34.34.0 is directly connected, FastEthernet0/01.0.0.0/24 is subnetted, 1 subnets
B 1.1.1.0 [200/0] via 34.34.34.4, 00:00:472.0.0.0/24 is subnetted, 1 subnets
B 2.2.2.0 [20/0] via 23.23.23.2, 00:28:0023.0.0.0/24 is subnetted, 1 subnets
C 23.23.23.0 is directly connected, FastEthernet0/112.0.0.0/24 is subnetted, 1 subnets
B 12.12.12.0 [20/0] via 23.23.23.2, 02:22:5414.0.0.0/24 is subnetted, 1 subnets
B 14.14.14.0 [200/0] via 34.34.34.4, 00:02:57
R4#show ip route Gateway of last resort is not set34.0.0.0/24 is subnetted, 1 subnets
C 34.34.34.0 is directly connected, FastEthernet0/01.0.0.0/24 is subnetted, 1 subnets
B 1.1.1.0 [20/0] via 14.14.14.1, 00:03:272.0.0.0/24 is subnetted, 1 subnets
B 2.2.2.0 [20/0] via 14.14.14.1, 00:03:2723.0.0.0/24 is subnetted, 1 subnets
B 23.23.23.0 [200/0] via 34.34.34.3, 00:03:2712.0.0.0/24 is subnetted, 1 subnets
B 12.12.12.0 [20/0] via 14.14.14.1, 00:03:2714.0.0.0/24 is subnetted, 1 subnets
C 14.14.14.0 is directly connected, FastEthernet0/1
使用tracert命令确认路由信息:
R3#traceroute 1.1.1.1Type escape sequence to abort.
Tracing the route to 1.1.1.11 34.34.34.4 4 msec 36 msec 24 msec2 14.14.14.1 24 msec 48 msec 48 msecR3#traceroute 2.2.2.2Type escape sequence to abort.
Tracing the route to 2.2.2.21 23.23.23.2 12 msec 12 msec 12 msec