这个实验应该是这些天BGP中最复杂的,能把它理解,并做出来,绝对是对自己有帮助的事情。这篇我写的很详细,下面给大家分享一下:
 
 
一、拓扑图:
 
 
 
二、配置步骤及说明:
1
、配置好各路由器的 IP地址,并且下面依次看一下协议的配置步骤:
R1(config-if)#router bgp 64512<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

R1(config-router)#net 130.130.1.0 mask 255.255.255.0

R1(config-router)#net 192.168.1.0

R1(config-router)#nei 192.168.1.2 remote 64513

 

R2(config-if)#router bgp 64513

R2(config-router)#net 192.168.1.0

R2(config-router)#nei 192.168.1.1 remote 64512

R2(config-router)#router ospf 1

R2(config-router)#net 172.16.1.0 0.0.0.255 area 0

 

R3(config-if)#router ospf 1

R3(config-router)#net 172.16.1.0 0.0.0.255 area 0

R3(config-router)#router bgp 64513

R3(config-router)#net 192.168.2.0

R3(config-router)#nei 192.168.2.2 remote 64514

 

R4(config-if)#router bgp 64514

R4(config-router)#net 192.168.2.0

R4(config-router)#nei 192.168.2.1 remote 64513

2、发现配置完之后,查看一下 R2R3的邻居关系:
R2 #sh ip bgp summary
………………

Neighbor        V    AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd

192.168.1.1     4 64512       9       9        3    0    0 00:05:40        2

 

R3#sh ip bgp summary

………………

Neighbor        V    AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd

192.168.2.2     4 64514       7       7        2    0    0 00:03:12        1

3、查看 R4的路由表,由于 R2R3之间是运行的是 OSPF协议,并没有 BGP的邻接关系。所以 R2R1学习到的 BGP路由 130.130.1.0/24的网络无法转发给 R3路由器,因此 R4上根本没有学习到任何的路由:
R4#sh ip route

………………

Gateway of last resort is not set

C    192.168.2.0/24 is directly connected, Serial1/0  (只有直连链路,并没有学习到路由)

4、为了让两边都能学到完整的路由,我们在 R2R3上对 BGPOSPF互做重分发:
R2(config)#router bgp 64513

R2(config-router)#red ospf 1 match external internal (将OSPF内部和外部类型都重分发到BGP中)

R2(config-router)#router ospf 1

R2(config-router)#red bgp 64513 subnets   (将BGP AS 64513自治系统重分发到OSPF进程当中)

 

R3(config)#router bgp 64513

R3(config-router)#redistribute ospf 1 match external internal

R3(config-router)#router ospf 1

R3(config-router)#redistribute bgp 64513 subnets

5、现在两边的路由都能学到了。并且重分发时没指定类型, R3学习到的外部路由默认以 O E2呈现。我们来看一下 R3R4的路由表:
R3#sh ip route

………………

Gateway of last resort is not set

 172.16.0.0/24 is subnetted, 1 subnets

C       172.16.1.0 is directly connected, FastEthernet0/0

     130.130.0.0/24 is subnetted, 1 subnets

O E2    130.130.1.0 [110/1] via 172.16.1.1, 00:05:33, FastEthernet0/0

O E2 192.168.1.0/24 [110/1] via 172.16.1.1, 00:05:33, FastEthernet0/0

C    192.168.2.0/24 is directly connected, Serial1/1

 

R4#sh 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:10:10

     130.130.0.0/24 is subnetted, 1 subnets

B       130.130.1.0 [20/1] via 192.168.2.1, 00:10:10

B    192.168.1.0/24 [20/1] via 192.168.2.1, 00:10:10

C    192.168.2.0/24 is directly connected, Serial1/0

6、查看一下 R3R4BGP数据库发现:
R3#sh ip bgp

BGP table version is 5, 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

*> 130.130.1.0/24   172.16.1.1               1         32768 ?(发现没有AS-PATH)

*> 172.16.1.0/24    0.0.0.0                  0         32768 ?

*> 192.168.1.0      172.16.1.1               1         32768 ?
*  192.168.2.0      192.168.2.2              0       0 64514 i

*>                  0.0.0.0                  0         32768 i

 

R4#sh 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 ?(R4只学到AS没有PATH

*> 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

7、从上图发现 R3R4的拓扑数据库不完整,同时我们也应该反推出 R1R2学习到路由的 AS-PATH属性也不会是完整的:
R1#sh ip bgp

…………

Origin codes: i - IGP, e - EGP, ? - incomplete

 

   Network          Next Hop            Metric LocPrf Weight Path

*> 130.130.1.0/24   0.0.0.0                  0         32768 i

*> 172.16.1.0/24    192.168.1.2              0             0 64513 ?

*  192.168.1.0      192.168.1.2              0             0 64513 i

*>                  0.0.0.0                  0         32768 i

*> 192.168.2.0      192.168.1.2              1             0 64513 ?

 

R2#sh ip bgp

………………

Origin codes: i - IGP, e - EGP, ? - incomplete

 

   Network          Next Hop            Metric LocPrf Weight Path

*> 130.130.1.0/24   192.168.1.1              0             0 64512 i

*> 172.16.1.0/24    0.0.0.0                  0         32768 ?

*  192.168.1.0      192.168.1.1              0             0 64512 i

*>                  0.0.0.0                  0         32768 i

*> 192.168.2.0      172.16.1.2               1         32768 ?

8、由于 R2R3路由器把 BGP路由协议重分发到 OSPF中,而 OSPF不能够识别 BGP的路由 AS-PATH属性。传递中导致全网中看到 AS-PATH属性都不完整。
9
、下面将转到正题上:利用 路由标记解决 BGP中重分发时 AS-PATH属性不完整。因为路由标记是可以被所有路由协议识别。但怎样去实施呢?可以在 R2上将 BGPAS-PATH 转存到路由标记中,然后在 R3路由器上 重分发时再把路由标记中存储的 AS-PATH取出来还原到 BGP的路由中。
A
:下面我们到 R2上将 BGPAS-PATH转存到路由标记中:
R2(config)#route-map set_tag per 10 (建立一个名为set_tag路由图)

R2(config-route-map)#set automatic-tag(设置自动计算标记值,针对的是AS-PATH属性值)

R2(config-route-map)#router bgp 64513

R2(config-router)#table-map set_tag (将刚才设置的set_tag 映射到路由表中,也就是转存一下)

B:再到 R3重分发时提取路由标记:
R3(config)#route-map get_tag per 10(建立一个路由图名为get_tag

R3(config-route-map)#set as-path tag(从路由标记中提取AS-PATH属性还原到BGP路由数据库中)

R3(config-route-map)#router bgp 64513

R3(config-router)#red ospf 1 match external internal route-map get_tag(利用重分发匹配外部和内部路由ospf 路由指向route-map转存BGPAS-PATH属性 )

10、现在来看一下 R3R4BGP数据库。
R3#sh ip bgp

………………

Origin codes: i - IGP, e - EGP, ? - incomplete

 

   Network          Next Hop            Metric LocPrf Weight Path

*> 130.130.1.0/24   172.16.1.1               1         32768 64512 ? AS-PATH有了,但起源属性还是不完整

*> 172.16.1.0/24    0.0.0.0                  0         32768 ?
*> 192.168.1.0      172.16.1.1               1         32768 ?

*  192.168.2.0      192.168.2.2              0             0 64514 i

*>                  0.0.0.0                  0         32768 i

R4#sh ip bgp

………………

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 ? (都显示?号为不完整)

*> 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

11、在 R3设置起源,让 R4能学到完整的 BGP数据库:
R3(config)#route-map set_origin per 10 (针对起源再建立一个名为set_origin的路由图)

R3(config-route-map)#set origin igp (设置起源属性为IGP

R3(config-route-map)#router bgp 64513

R3(config-router)#nei 192.168.2.2 route-map set_origin out(利用路由图调用起源属性,指定下游out方向)

12、现在来看一下 R4BGP数据库 ,发现已经完整了:
R4#sh ip bgp

………………

   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      192.168.2.1              0             0 64513 i

*>                  0.0.0.0                  0         32768 i