32. Understand BGP Sychronization Rule

1、深入理解BGP的同步规则。
 
网络图:

image.png


配置各路由器IP地址等基本信息。

正确配置BGP协议。

 

在R3上查看IP路由协议情况:

R3#show ip protocol
Routing Protocol is "bgp 64513"
  Outgoing update filter list for all interfaces is not set
  Incoming update filter list for all interfaces is not set
  IGP synchronization is disabled  --------->禁用同步规则
  Automatic route summarization is disabled
  Neighbor(s):
    Address          FiltIn FiltOut DistIn DistOut Weight RouteMap
    10.1.255.5                                           
    10.1.255.10                                          
  Maximum path: 1
  Routing Information Sources:
    Gateway         Distance      Last Update
    10.1.255.5           200      00:06:23
    10.1.255.10          200      00:02:06
  Distance: external 20 internal 200 local 200

 

查看R2和R4的路由表:

R2#show ip route
Gateway of last resort is not set

     10.0.0.0/30 is subnetted, 3 subnets
C       10.1.255.4 is directly connected, Serial0/1
C       10.1.255.0 is directly connected, Serial0/0
B       10.1.255.8 [200/0] via 10.1.255.6, 00:04:49
     130.130.0.0/24 is subnetted, 1 subnets
B       130.130.1.0 [20/0] via 10.1.255.1, 00:08:00

 

R4#show ip route
Gateway of last resort is not set

     10.0.0.0/30 is subnetted, 3 subnets
B       10.1.255.4 [200/0] via 10.1.255.9, 00:06:15
C       10.1.255.12 is directly connected, Serial0/1
C       10.1.255.8 is directly connected, Serial0/0
     150.150.0.0/24 is subnetted, 1 subnets
B       150.150.1.0 [20/0] via 10.1.255.14, 00:03:47   
----->两个路由器都没有学习完整

 

原因解释:BGP规则之一,从iBGP对等体学习到的路由,不会通告给其它的iBGP对等体。所以R2和R4不能学习到完整的路由。

 

如果让64513中形成全互连(不是物理上的直接互连),即可让R2和R4学习到完整的路由。

 

在R2和R4上配置iBGP邻居关系:

R2(config)#router bgp 64513
R2(config-router)#neighbor 10.1.255.10 remote 64513  ----->指向R4
R2(config-router)#exit

 

R4(config)#router bgp 64513
R4(config-router)#neighbor 10.1.255.5 remote 64513   ----->指向R2
R4(config-router)#exit

 

再看R2和R4的路由表:

R2#show ip route
Gateway of last resort is not set

     10.0.0.0/30 is subnetted, 4 subnets
C       10.1.255.4 is directly connected, Serial0/1
C       10.1.255.0 is directly connected, Serial0/0
B       10.1.255.12 [200/0] via 10.1.255.10, 00:02:58
B       10.1.255.8 [200/0] via 10.1.255.6, 00:19:06
     130.130.0.0/24 is subnetted, 1 subnets
B       130.130.1.0 [20/0] via 10.1.255.1, 00:22:17
     150.150.0.0/24 is subnetted, 1 subnets
B       150.150.1.0 [200/0] via 10.1.255.14, 00:02:53

 

R4#show ip route
Gateway of last resort is not set

     10.0.0.0/30 is subnetted, 4 subnets
B       10.1.255.4 [200/0] via 10.1.255.5, 00:00:22
B       10.1.255.0 [200/0] via 10.1.255.5, 00:00:22
  ----->不是最佳路由
C       10.1.255.12 is directly connected, Serial0/1
C       10.1.255.8 is directly connected, Serial0/0
     150.150.0.0/24 is subnetted, 1 subnets
B       150.150.1.0 [20/0] via 10.1.255.14, 00:15:53 
---->还没学习完整,130段的没有

 

查看BGP内部路由表:

R4#show ip bgp
BGP table version is 55, local router ID is 10.1.255.13
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
* i10.1.255.0/30    10.1.255.5               0    100      0 i
* i10.1.255.4/30    10.1.255.5               0    100      0 i
*>i                 10.1.255.9               0    100      0 i
*> 10.1.255.8/30    0.0.0.0                  0         32768 i
* i                 10.1.255.9               0    100      0 i
*  10.1.255.12/30   10.1.255.14              0             0 64514 i
*>                  0.0.0.0                  0         32768 i
* i130.130.1.0/24   10.1.255.1               0    100      0 64512 i

                                       ---->学习到130段的,但认为不是最佳的
*> 150.150.1.0/24   10.1.255.14              0             0 64514 i

 

单独查看130.130.1.0/24网络路由:

R4#show ip bgp 130.130.1.0
BGP routing table entry for 130.130.1.0/24, version 0
Paths: (1 available, no best path)
  Not advertised to any peer
  64512
    10.1.255.1 (inaccessible) from 10.1.255.5 (10.1.255.5)  ----->下一跳不可达
      Origin IGP, metric 0, localpref 100, valid, internal

 

再看看其它的:

R4#show ip bgp 10.1.255.0
BGP routing table entry for 10.1.255.0/30, version 88
Paths: (1 available, best #1, table Default-IP-Routing-Table)
Flag: 0x820
  Not advertised to any peer
  Local
    10.1.255.5 from 10.1.255.5 (10.1.255.5)   -------->下一跳不可达
      Origin IGP, metric 0, localpref 100, valid, internal, best

R4#ping 10.1.255.1

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.1.255.1, timeout is 2 seconds:
.....   --------->不通
Success rate is 0 percent (0/5)

 

原因是:BGP选路规则之一,当两条路由度量值都想等时,而且都来自于相同自治系统的iBGP邻居,会优先选择route id较小的iBGP邻居的路由。

 

解决方法:

 

配置一个较高的router id给R2:

R2(config)#router bgp 64513
R2(config-router)#bgp router-id 172.16.255.254
R2(config-router)#end

 

等重新收敛后再查看R4的路由表:

R4#show ip route
Gateway of last resort is not set

     10.0.0.0/30 is subnetted, 4 subnets
B       10.1.255.4 [200/0] via 10.1.255.9, 00:01:13
B       10.1.255.0 [200/0] via 10.1.255.5, 00:00:36
C       10.1.255.12 is directly connected, Serial0/1
C       10.1.255.8 is directly connected, Serial0/0
     130.130.0.0/24 is subnetted, 1 subnets
B       130.130.1.0 [200/0] via 10.1.255.1, 00:00:31
     150.150.0.0/24 is subnetted, 1 subnets
B       150.150.1.0 [20/0] via 10.1.255.14, 00:38:35
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 = 32/82/120 ms

 

在R2、R3和R4上配置OSPF路由协议并开启同步规则:

R2(config)#router bgp 64513
R2(config-router)#synchronization 
R2(config-router)#exit
R2(config)#router ospf 1
R2(config-router)#network 10.1.255.0 0.0.0.3 a 0
R2(config-router)#network 10.1.255.4 0.0.0.3 a 0
R2(config-router)#exit

 

R3(config)#router bgp 64513
R3(config-router)#synchronization
R3(config-router)#exit
R3(config)#router ospf 1
R3(config-router)#network 10.1.255.4 0.0.0.3 a 0
R3(config-router)#network 10.1.255.8 0.0.0.3 a 0
R3(config-router)#end

 

R4(config)#router bgp 64513
R4(config-router)#synchronization
R4(config-router)#exit
R4(config)#router ospf 1
R4(config-router)#network 10.1.255.8 0.0.0.3 a 0
R4(config-router)#network 10.1.255.12 0.0.0.3 a 0
R4(config-router)#end

 

查看R1和R2路由表,确认是否学习以150.150.1.0/24网络的路由:

R1#show ip route
Gateway of last resort is not set

     10.0.0.0/30 is subnetted, 4 subnets
B       10.1.255.4 [20/0] via 10.1.255.2, 00:17:01
C       10.1.255.0 is directly connected, Serial0/0
B       10.1.255.12 [20/0] via 10.1.255.2, 00:01:43
B       10.1.255.8 [20/0] via 10.1.255.2, 00:03:10
     130.130.0.0/24 is subnetted, 1 subnets
C       130.130.1.0 is directly connected, Loopback0  
 ----->没学到

 

R2#show ip route
Gateway of last resort is not set

     10.0.0.0/30 is subnetted, 4 subnets
C       10.1.255.4 is directly connected, Serial0/1
C       10.1.255.0 is directly connected, Serial0/0
O       10.1.255.12 [110/192] via 10.1.255.6, 00:03:08, Serial0/1
O       10.1.255.8 [110/128] via 10.1.255.6, 00:03:08, Serial0/1
     130.130.0.0/24 is subnetted, 1 subnets
B       130.130.1.0 [20/0] via 10.1.255.1, 00:18:21   
-------->也不完全

 

查看R2的BGP表:

R2#show ip bgp
BGP table version is 14, local router ID is 172.16.255.254
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
*> 10.1.255.0/30    0.0.0.0         0         32768 i
*               10.1.255.1       0      0      64512 i
*> 10.1.255.4/30    0.0.0.0         0         32768 i
* i             10.1.255.6        0    100      0 i
r i10.1.255.8/30    10.1.255.10      0    100      0 i
r>i             10.1.255.6       0    100      0 i
r>i10.1.255.12/30   10.1.255.10       0    100      0 i
*> 130.130.1.0/24   10.1.255.1       0             0 64512 i
* i150.150.1.0/24   10.1.255.14      0    100      0 64514 i

最后一行表明BGP已经学习到150.150.1.0/24的路由,但由于未知的原因,导致此路由不能使用。

 

查看R2对150.150.1.0/24的描述:

R2#show ip bgp 150.150.1.0
BGP routing table entry for 150.150.1.0/24, version 10
Paths: (1 available, no best path)
  Not advertised to any peer   ---->被标记为不通告状态
  64514
    10.1.255.14 (metric 192) from 10.1.255.10 (10.1.255.13)
      Origin IGP, metric 0, localpref 100, valid, internal, not synchronized  
---->路由不同步

 

原因是:BGP的同步规则指出BGP路由器不应使用通过IBGP获悉的路由或将其通告给外部邻居,除非该路由是本地的或是通过IGP获悉的。

 

可使用重分发解决。

 

在R4上,重发分到OSPF中:

R4(config)#router ospf 1
R4(config-router)#re bgp 64513 me 200 subnets
R4(config-router)#end

 

再次查看R2对150.150.1.0/24的描述:

R2#show ip bgp 150.150.1.0
BGP routing table entry for 150.150.1.0/24, version 16
Paths: (1 available, best #1, table Default-IP-Routing-Table, RIB-failure(17))
Flag: 0x820
  Advertised to update-groups:
     1         
  64514
    10.1.255.14 (metric 192) from 10.1.255.10 (10.1.255.13)
      Origin IGP, metric 0, localpref 100, valid, internal, synchronized, best

       ---->已经同步,认为是最佳路由

 

查看R1路由表:

R1#show ip route
Gateway of last resort is not set

     10.0.0.0/30 is subnetted, 4 subnets
B       10.1.255.4 [20/0] via 10.1.255.2, 00:30:53
C       10.1.255.0 is directly connected, Serial0/0
B       10.1.255.12 [20/0] via 10.1.255.2, 00:15:35
B       10.1.255.8 [20/0] via 10.1.255.2, 00:17:02
     130.130.0.0/24 is subnetted, 1 subnets
C       130.130.1.0 is directly connected, Loopback0
     150.150.0.0/24 is subnetted, 1 subnets
B       150.150.1.0 [20/0] via 10.1.255.2, 00:03:12   
----->已经完全

R1#ping 150.150.1.1

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 150.150.1.1, timeout is 2 seconds:
.....   ------>还没完
Success rate is 0 percent (0/5)

同样也要在R2上配置重分发,解决R4 BGP学习130段网络的问题。

 

但是在R2上配置完重分发后,R1到150.150.1.0/24和R5到130.130.1.0/24网络相互不通,检查后发现R5上没有到130段的路由,在R2上把BGP的router-id删除(把172段的换回10段的,也就是减小),在R4上先后用clear ip bgp x.x.x.x重置与R2和R5的邻居关系后正常,其中原因还不太明朗,但是应该是和router-id、同步有关。

 


发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

桂ICP备19000498号-3