1、解决 BGP 与 IGP 在做路由重发布时,BGP AS-PATH 属性丢失的问题。
2、掌握使用路由标记存储 BGP 路径属性配置方法。
拓扑图:
配置各路由器的IP地址等基本信息,测试互连可达。
配置各路由器的BGP协议,其中R2和R3之间只配置OSPF,不配置BGP。
R2和R3的OSPF配置:
R2(config)#router ospf 1
R2(config-router)#network 172.16.1.0 0.0.0.255 a 0
R2(config-router)#exit
R3(config)#router ospf 1
R3(config-router)#network 172.16.1.0 0.0.0.255 a 0
R3(config-router)#exit
确认R2和R3的邻居关系:
R3#show ip ospf nei
Neighbor ID Pri State Dead Time Address Interface
192.168.1.2 1 FULL/BDR 00:00:31 172.16.1.1 Ethernet0/0
配置R1与R2、R3与R4的BGP协议。R2和R3之间没有任何BGP邻居关系。
其中R2和R3的配置如下:
R2(config)#router bgp 64513
R2(config-router)#neighbor 192.168.1.1 remote 64512
R2(config-router)#network 192.168.1.0
R2(config-router)#end
R3(config)#router bgp 64513
R3(config-router)#neighbor 192.168.2.2 remote 64514
R3(config-router)#network 192.168.2.0
R3(config-router)#end
确认R2、R3的邻居关系(其实在控制台消息中已经体现):
R2#show ip bgp summary
……………
Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
192.168.1.1 4 64512 9 8 4 0 0 00:04:04 2
R2#
R3#show ip bgp summary
……………
Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
192.168.2.2 4 64514 6 6 2 0 0 00:02:03 1
R3#
查看R4路由表:
R4#show ip route
Gateway of last resort is not set
C 192.168.2.0/24 is directly connected, Serial0/0
由于R2和R3没有BGP邻居关系,所以R2学习到的130网段的路由在R3上不能学习到,所以R4上也学习不到。
在R2和R3上配置BGP和OSPF的重分发:
R2(config)#router ospf 1
R2(config-router)#redistribute bgp 64513 subnets
R2(config-router)#exit
R2(config)#router bgp 64513
R2(config-router)#redistribute ospf 1 match external internal
---->OSPF内部类型和外部类型的路由重发布到BGP 64513
R2(config-router)#end
R3(config)#router ospf 1
R3(config-router)#redistribute bgp 64513 subnets
R3(config-router)#exit
R3(config)#router bgp 64513
R3(config-router)#redistribute ospf 1 match external internal
R3(config-router)#end
查看R4,确认重分发:
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.1, 00:48:28
130.130.0.0/24 is subnetted, 1 subnets
B 130.130.1.0 [20/1] via 192.168.2.1, 00:48:28
B 192.168.1.0/24 [20/1] via 192.168.2.1, 00:00:21
C 192.168.2.0/24 is directly connected, Serial0/0
查看R4中的BGP数据库:
R4#show ip bgp
BGP table version is 5, local router ID is 192.168.2.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
*> 130.130.1.0/24 192.168.2.1 1 0 64513 ?
*> 172.16.1.0/24 192.168.2.1 0 0 64513 ?
*> 192.168.1.0 192.168.2.1 1 0 64513 ?
* 192.168.2.0 192.168.2.1 0 0 64513 i ---->AS-PATH信息不完整
*> 0.0.0.0 0 32768 i
产生此问题的主要原因是:由于R2路由器把BGP路由协议重分发到OSPF中,而OSPF不能识别BGP的路由AS-PATH属性,所以在R4上查看重分发路由的AS-PATH是不完整的。
解决这个问题的关键:由于路由标记可以被所有的路由协议识别,因此,可以在重分发前把BGP的AS-PATH转存到路由标记中,然后在R4路由器上再把路由标记中存储的AS-PATH取出来还原到BGP的路由中。
在R2上实施路由标记的配置:
R2(config)#route-map set-tag per 10
R2(config-route-map)#set automatic-tag ---->设置自动计算路由标记
R2(config-route-map)#exit
R2(config)#router bgp 64513
R2(config-router)#table-map set-tag
R2(config-router)#exit
R3(config)#route-map get-tag per 10
R3(config-route-map)#set as-path tag ----->把AS-PATH属性从路由标记中取出,还原到BGP的路由数据库中
R3(config-route-map)#exit
R3(config)#router bgp 64513
R3(config-router)#redistribute ospf 1 match ex in route-map get-tag --->重分发时完成AS-PATH的转存工作
R3(config-router)#exit
查看R4上的BGP数据库:
R4>show ip bgp
BGP table version is 5, local router ID is 192.168.2.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
*> 130.130.1.0/24 192.168.2.1 1 0 64513 64512 i ---->已经识别出路径
*> 172.16.1.0/24 192.168.2.1 0 0 64513 ?
*> 192.168.1.0 192.168.2.1 1 0 64513 ?
* 192.168.2.0 192.168.2.1 0 0 64513 i
*> 0.0.0.0 0 32768 i
源头信息不完整,在R3上继续:
R3(config)#route-map set-origin per 10
R3(config-route-map)#set origin igp
R3(config-route-map)#exit
R3(config)#router bgp 64513
R3(config-router)#neighbor 192.168.2.2 route-map set-origin out
R3(config-router)#exit
再次查看R4上的BGP数据库;
R4#show ip bgp
BGP table version is 7, local router ID is 192.168.2.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
*> 130.130.1.0/24 192.168.2.1 1 0 64513 64512 i
*> 172.16.1.0/24 192.168.2.1 0 0 64513 i
*> 192.168.1.0 192.168.2.1 1 0 64513 i ---->已经完整
*> 192.168.2.0 0.0.0.0 0 32768 i
* 192.168.2.1 0 0 64513 i
确认网络可达:
R4#ping 130.130.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 130.130.1.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 56/99/156 ms
完成。