一、拓扑图:
二、详细说明与配置:
1
、配置各接口IP地址,以及R1R2运行RIP V2,并关闭自动汇总,保证链路的互通性:
2
、我们先在R1上配置BGP,这次我们不用对端接口地址来建立bgp的邻居,而是用loopback地址来建立,因为大家知道loopback地址是不会down 的,对于bgp而言这种方式是最好的了。这样有利于bgp邻居关系的稳健性。下面看一下R1的配置:<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

R1(config)#router bgp 64512

R1(config-router)#net 172.16.0.0 mask 255.255.255.0

R1(config-router)#net 172.16.1.0 mask 255.255.255.0

R1(config-router)#net 172.16.255.0 mask 255.255.255.252

R1(config-router)#nei 172.16.16.1 remote 64512(指定对端邻居的loopback0接口)

 
3 、我们先不管能不能建立起邻居,先在R2上配置,看一下只指定邻居回环地址之后,能不能建立起bgp邻居:
R2(config)#router bgp 64512

R2(config-router)#net 172.16.255.0 mask 255.255.255.252

R2(config-router)#net 172.16.16.0 mask 255.255.255.0

R2(config-router)#net 10.1.255.0 mask 255.255.255.252

R2(config-router)#nei 172.16.0.1 remote 64512 (指定对端邻居的loopback0接口)

4 、查看一下有没有建立起邻居:
R1#show ip bgp sum

BGP router identifier 172.16.1.1, local AS number 64512

BGP table version is 1, main routing table version 1

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

172.16.16.1     4 64512       0       0        0    0    0 never    Active (还在尝试连接,发现并没有建立起来)

5 、我们在R1debug ip bgp all看一下:
R1#debug ip bgp all

BGP debugging is on for all address families

R1#

*Mar  1 02:49:46.535: BGP: 172.16.16.1 open active, local address 172.16.255.1

*Mar  1 02:49:46.627: BGP: 172.16.16.1 open failed: Connection refused by remote host, open active delayed 29991ms (35000ms max, 28% jitter) (发现被远程的主机拒绝了)

6 、看来只单指定回环口的邻居并不行,我们还需要在两边指定用loopback接口做更新源:
R1(config-router)#nei 172.16.16.1 update-source loopback 0

R2(config-router)#nei 172.16.0.1 update-source lo0(分别在R1,R2指定用自己的lo0接口和对端建邻居)

7 、再来看一下邻居关系:

R1#show ip bgp summary

BGP router identifier 172.16.1.1, local AS number 64512

BGP table version is 7, main routing table version 7

5 network entries using 585 bytes of memory

6 path entries using 312 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 1269 total bytes of memory

BGP activity 8/3 prefixes, 9/3 paths, scan interval 60 secs

 

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

172.16.16.1     4 64512      12      12        7    0    0 00:07:26        3 (邻居起来了)

二、R1R2建立起来了邻居关系,拓扑中R2R3并不在同一个AS当中。那么R2R3该怎样去做呢?
1
R2R3在不同的AS当中,我们需要指定ebgp多跳,并且由于R3没有运行RIP V2协议,为了保证它们之间有TCP连接关系,我们到时候用静态路由去指定好了。看一下R1的配置:
R2(config)#ip route 192.168.0.0 255.255.255.0 10.1.255.2

R2(config-router)#net 10.1.255.0 mask 255.255.255.252

R2(config-router)#nei 192.168.0.1 remote 64513

R2(config-router)#nei 192.168.0.1 update-source lo0

R2(config-router)#nei 192.168.0.1 ebgp-multihop 2

2、在R3上的配置:

R3(config)#ip route 172.16.16.0 255.255.255.0 10.1.255.1(建静态由路保证指定地址TCP可达)

R3(config-router)#net 192.168.0.0

R3(config-router)#net 192.168.1.0 (注入直连网络到BGP进程当中,有类地址没带子网发布)

R3(config-router)#net 10.1.255.0 mask 255.255.255.252(无类地址带子网发布)

R3(config-router)#nei 172.16.16.1 remote 64512

R3(config-router)#nei 172.16.16.1 update-source lo0 (用本地的lo0和对端指定邻居)

R3(config-router)#nei 172.16.16.1 ebgp-multihop 2 (指出ebgp的邻居地址存在多跳特性)

3 、再到R2上看一下bgp的邻居汇总:
R2#show ip bgp summary

BGP router identifier 172.16.16.1, local AS number 64512

BGP table version is 24, main routing table version 24

7 network entries using 819 bytes of memory

8 path entries using 416 bytes of memory

4/3 BGP path/bestpath attribute entries using 496 bytes of memory

1 BGP AS-PATH entries using 24 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 1755 total bytes of memory

BGP activity 9/2 prefixes, 13/5 paths, scan interval 60 secs

 

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

172.16.0.1      4 64512      41      47       24    0    0 00:36:55        3

192.168.0.1     4 64513      14      20       24    0    0 00:03:32        3  (至此两条邻居都能看到了)

 
三、设置邻居的下一跳:
1、现在我们再来看一下R1R2R3bgp路由表:
R1#sh ip route bgp

     10.0.0.0/30 is subnetted, 1 subnets

B       10.1.255.0 [200/0] via 172.16.16.1, 01:16:50 (发现只有一条bgp路由)

 

R2#show ip route

Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP

       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area

       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2

       E1 - OSPF external type 1, E2 - OSPF external type 2

       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2

       ia - IS-IS inter area, * - candidate default, U - per-user static route

       o - ODR, P - periodic downloaded static route

 

Gateway of last resort is not set

 

     172.16.0.0/16 is variably subnetted, 4 subnets, 2 masks

C       172.16.255.0/30 is directly connected, FastEthernet0/0

C       172.16.16.0/24 is directly connected, Loopback0

R       172.16.0.0/24 [120/1] via 172.16.255.1, 00:00:16, FastEthernet0/0

R       172.16.1.0/24 [120/1] via 172.16.255.1, 00:00:16, FastEthernet0/0 (ibgp内以RIP来走)

     10.0.0.0/30 is subnetted, 1 subnets

C       10.1.255.0 is directly connected, Serial1/1

S    192.168.0.0/24 [1/0] via 10.1.255.2

B    192.168.1.0/24 [20/0] via 192.168.0.1, 02:20:11 (学到了域外的ebgp)

R3#sh ip route bgp

     172.16.0.0/16 is variably subnetted, 4 subnets, 2 masks

B       172.16.255.0/30 [20/0] via 172.16.16.1, 01:16:15

B       172.16.0.0/24 [20/0] via 172.16.16.1, 01:16:15

B       172.16.1.0/24 [20/0] via 172.16.16.1, 01:16:15  (能够全部学到,并以BGP呈现)

2 、因为R1R2运行了RIP 协议,R3运行的是静态路由。而且BGP运行的是两个AS,从上面的各路由器学到的bgp邻居的情况,我们看到了R3能学到所有的bgp路由,但R1只学到了一条路由,原因是BGP speakerIBGP获得的路由不向它的IBGP相邻体通告,所以R2并没有把学到的ebgp的路由通告给R1,那么我们只需要在R2上指定从R3那边来的路由指定下一跳为自己,把它通告给R1

R2(config-router)#nei 172.16.0.1 next-hop-self

3 、现在再来看一下R1bgp路由表:
R1#sh ip route bgp

     10.0.0.0/30 is subnetted, 1 subnets

B       10.1.255.0 [200/0] via 172.16.16.1, 02:43:56

B    192.168.0.0/24 [200/0] via 172.16.16.1, 00:00:02

B    192.168.1.0/24 [200/0] via 172.16.16.1, 00:00:02  (现在学到了三条了。)

R1#

 
 
四、 总结:因为只要路由器开启,回环口一直都会是up状态。用回环地址去建立bgp连接能够提高bgp邻居关系的稳健性,但需要注意的是配置时需保证到loopback地址的TCP可达性,而且还要指出用本地回环地址和对端建立邻居,当和ebgp端跨子网建立邻居时,则需要使用ebgp多跳功能来指定ebgp邻居,最大支持255跳。BGP speakerIBGP获得的路由不向它的IBGP相邻体通告,所以我们要在边缘的路由器上指定下一跳为自己进行路由的转发通告。在BGP中所说的下一跳,是指下一跳AS,而并非是下一跳路由器。由EBGP学来的路由信息,在传递给IBGP邻居时,不改变其下一跳属性值。