一 各路由器的基本配置
RA#sh run
interface Loopback0
 ip address 1.1.1.1 255.255.255.0               
interface Serial0
 ip address 192.1.1.1 255.255.255.0
!         
       
router bgp 100                                         // 启动BGP  AS 100
 no synchronization
 bgp log-neighbor-changes
 neighbor 192.1.1.2 remote-as 200         //与AS 200 中的RB建立EBGP邻接关系
 no auto-summary
! !!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!
RB#sh run
!
interface Loopback0
 ip address 2.2.2.2 255.255.255.0
interface Ethernet0
 ip address 193.1.1.1 255.255.255.0       
interface Serial0
 ip address 192.1.1.2 255.255.255.0
 clockrate 64000
!        
router bgp 200                                //启动BGP AS 200
 neighbor 192.1.1.1 remote-as 100  //与AS100中的RA建立EBGP邻接关系
 neighbor 193.1.1.2 remote-as 200  //与本AS中的RC建立IBGP邻接关系
! !!!!!!!!!!!!!!!!!!!
!!!!!!!!!!
RC#sh run

interface Loopback0
 ip address 3.3.3.3 255.255.255.0      
interface Ethernet0
 ip address 193.1.1.2 255.255.255.0
 !        
router bgp 200                                //启动BGP进程,AS 200
 no synchronization
 bgp log-neighbor-changes
 neighbor 193.1.1.1 remote-as 200  //与本AS中的RB建立IBGP邻接关系
 no auto-summary

二 测试邻居关系
RB#sh ip bgp neighbors
BGP neighbor is 192.1.1.1remote AS 100, external link
  BGP version 4,
remote router ID 1.1.1.1
  BGP state = Established, up for 00:01:04
  Last read 00:00:04, hold time is 180, keepalive interval is 60 seconds
  Neighbor capabilities:
    Route refresh: advertised and received
    Address family IPv4 Unicast: advertised and received
  Received 5 messages, 0 notifications, 0 in queue
  Sent 4 messages, 0 notifications, 0 in queue
  Route refresh request: received 0, sent 0
  Minimum time between advertisement runs is 30 seconds
Connections established 1; dropped 0
  Last reset never
Connection state is ESTAB, I/O status: 1, unread input bytes: 0
Local host: 192.1.1.2, Local port: 11001
Foreign host: 192.1.1.1, Foreign port: 179

         
BGP neighbor is 193.1.1.2,  remote AS 200, internal link
  BGP version 4,
remote router ID 3.3.3.3
  BGP state = Established, up for 00:00:34
  Last read 00:00:34, hold time is 180, keepalive interval is 60 seconds
  Neighbor capabilities:
    Route refresh: advertised and received
    Address family IPv4 Unicast: advertised and received
  Received 4 messages, 0 notifications, 0 in queue
  Sent 3 messages, 0 notifications, 0 in queue
  Route refresh request: received 0, sent 0
  Minimum time between advertisement runs is 5 seconds
  Connections established 1; dropped 0
  Last reset never
Connection state is ESTAB, I/O status: 1, unread input bytes: 0
Local host: 193.1.1.1, Local port: 179
Foreign host: 193.1.1.2, Foreign port: 37817

说明:通过在RB上输入:show ip bgp neigbors 这条命令可以看到RB已经和RA和RC建立了邻居关系。输出中的蓝色带下划线的部分从不同的角度都表示了这种邻居关系已经建立。还可以看出BGP协议是使用TCP协议通过179端口与邻居建立连接的,这种连接关系一旦建立就会一直存在下去,除非路由器失效。

三 测试网络的宣告
     一个路由器若要向他的BGP邻居路由器宣告一个网络,可以用network命令或者用重发布,使BGP进程能知道该路由,另外,被一个路由器宣告的网络必须存在于该路由器的IP路由表中。
     在本实验中要将RA的1.1.1.0/24网络宣告到BGP进程中;首先在RA中查看该网络是否在路由表中。

RA#sh ip route
     1.0.0.0/24 is subnetted, 1 subnets
C       1.1.1.0 is directly connected, Loopback0   //1.1.1.0/24存在于路由表中
C    192.1.1.0/24 is directly connected, Serial0

下面进行宣告。
RA# conf  t 
RA(config)#router bgp 100
RA(config-router)#network 1.1.1.0 mask 255.255.255.0 // 将网络宣告到BGP中
*************************************************
*************************************************
RB#sh ip bgp                                             //显示RB上的IP BGP表
BGP table version is 4, local router ID is 2.2.2.2
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal
Origin codes: i - IGP, e - EGP, ? - incomplete
   Network          Next Hop            Metric LocPrf Weight Path
*> 1.1.1.0/24       192.1.1.1                0             0 100 i
该输出表示 1.1.1.0/24通过192.1.1.1已经被RB学习到了,*表示该条目有效,〉表示该条目是最佳的。
*********************************************************************
RB#sh ip route
Gateway of last resort is not set
     1.0.0.0/24 is subnetted, 1 subnets
B       1.1.1.0 [20/0] via 192.1.1.1, 02:49:03
     2.0.0.0/24 is subnetted, 1 subnets
C       2.2.2.0 is directly connected, Loopback0
C    193.1.1.0/24 is directly connected, Ethernet0
C    192.1.1.0/24 is directly connected, Serial0
RB的路由表也表示1.1.1.0/24这条路由已经被学习到了。
**********************************************************************
下面我们来看RC
RC#sh ip bgp
BGP table version is 1, local router ID is 3.3.3.3
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
* i1.1.1.0/24       192.1.1.1                0    100      0 100 i
RC的BGP表也学到了这条路由,i表示这是通过IBGP进程学习到的。

RC#sh ip route
     3.0.0.0/24 is subnetted, 1 subnets
C       3.3.3.0 is directly connected, Loopback0
C    193.1.1.0/24 is directly connected, Ethernet0
但是RC的路由表中我们却没有看到这条路由,我分析是1.1.1.0/24网络所指明的下一条地址并没有存在于RC的路由表中,因此RC并没有到该网络的路径。我觉得可以有两种方法来解决这个问题。
1 可以用路由重发布将BGP发布到AS 200 的IGP中(上次已经做过,这次省略)
2 在RB上强制将该路由的下一条改为193.1.1.1 从而使RC能学习到。
在这里我们使用第二种方法。
*********************************************************
RB(config)#router bgp 200
RB(config-router)#neighbor 193.1.1.2 next-hop-self
第二条语句表示RB将邻居193.1.1.2 的下一条指定为自己
****************************************************
RC#sh ip bgp 
BGP table version is 2, local router ID is 3.3.3.3
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
*>i1.1.1.0/24       193.1.1.1                0    100      0 100 i
这次的输出已经和上次有所不同,可以看到下一跳已经从192.1.1.1 变为193.1.1.1,而且路由条目的前缀多了一个>号,表示该条目已经是最佳的
*******************************************************
RC#sh ip route
Gateway of last resort is not set
     1.0.0.0/24 is subnetted, 1 subnets
B       1.1.1.0 [200/0] via 193.1.1.1, 00:02:00
     3.0.0.0/24 is subnetted, 1 subnets
C       3.3.3.0 is directly connected, Loopback0
C    193.1.1.0/24 is directly connected, Ethernet0

这次IP 路由表的输出,我们可以看到RC已经学习到了这条路由,下一条指向193.1.1.1 。但我们注意到这条BGP路由的管理距离值为200。而在RB的输出中该路由的管理距离值为20 。我想这是由于RB是通过EBGP学习到的该路由,而RC是通过IBGP学习到的该路由,从而管理距离值夜发生了变化。

**********************************************************************
**********************************************************************
 
总结:通过本次实验,我了解了BGP邻接关系的建立过程以及在宣告网端时的各种问题,比如说一条路由被路由器宣告到BGP中,该路由所指向的下一跳并不会因为学习该路由的路由器不同而发生改变。这所造成的结果是如果一台路由器与宣告该路由的路由器没有直连,它能通过BGP学习到该路由,但IGP却无法学到,因为该路由器的路由表中根本没有到达学习到的路由所指的下一条的路径。解决的方法是可以使用重发布或者使用neihbor X.X.X.X next--hop--self 这条命令强制更改到达所学习路由的下一条地址