首先,BGP本身是不支持负载均衡,但是在建立对等体会话时却变相利用IGP负载均衡来达到效果

一个路由器只能配置一个实例【也就是一个自治系统】只能配置一个BGP,BGP以单播来来传播更新
命令 neighbor   目的ip /对等体组  邻居所在自治系统号【如果相同,在同一范围,是IBGP,如果是不同自治系统号,则是EBGP】
BGP的基本操作 router bgp  AS【自治系统号】
neigh ip shudown   为防止路由抖动 若未指定源地址,则以自身逃出接口为源地址进行对接,且满足交叉相同原则,此原则放之四海皆用,自身的源和对端的目的IP必须保持一致才能建立TCP,建立BGP对等体会话,用自身的换回口,【满足逻辑接口,永远不会down掉
,R1R0之间建一个串口和一个以太口就可以了
实验的基本配置及现象
BGP不能满足负载均衡,
neighbor ip  update-source lo 0[源地址为lo 0]
router bgp as
neighbor ip remote-as num
neighbor ip update-source lo 0
router eigrp num
network ip [反演码]
若不设置更新源时,观禅实验现象
关于BGP的小实验1 - sonysony12345 - sonysony12345的博客
基本实验配置
Router(config)#ho r1
r1(config)#
r1(config)#no ip do lo
r1(config)#lin con 0
r1(config-line)#logg s
r1(config-line)#exec-t 0 0
r1(config-line)#
r1(config-line)#end
Enter configuration commands, one per line.  End with CNTL/Z.
r1(config)#int lo 0
r1(config-if)#ip add 1.1.1.1 255.255.255.255
r1(config-if)#int s1/0
r1(config-if)#ip add 12.1.1.1 255.255.255.0
r1(config-if)#no sh
r1(config-if)#
*Mar  1 00:02:45.855: %LINK-3-UPDOWN: Interface Serial1/0, changed state to up
*Mar  1 00:02:46.855: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial1/0, changed state to up
 
 
 配置r2
 Enter configuration commands, one per line.  End with CNTL/Z.
r2(config)#int lo 0
r2(config-if)#ip add 2.2.2.2 255.255.255.255
r2(config-if)#int s1/0
r2(config-if)#ip add 12.1.1.2 255.255.255.0
r2(config-if)#no shu
r2(config-if)#do
*Mar  1 00:03:48.451: %LINK-3-UPDOWN: Interface Serial1/0, changed state to up
*Mar  1 00:03:49.451: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial1/0, changed state to up
r2(config-if)#do ping 12.1.1.1
 
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 12.1.1.1, timeout is 2 seconds:
....!
Success rate is 20 percent (1/5), round-trip min/avg/max = 44/44/44 ms
r2(config-if)#do ping 12.1.1.1
 
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 12.1.1.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 12/43/76 ms
此时R2R1之间相互ping通,我们就可以起ospf 协议了
 
 
Enter configuration commands, one per line.  End with CNTL/Z.
r1(config)#router ospf 1
r1(config-router)#router-id 1.1.1.1
r1(config-router)#net 12.1.1.0 0.0.0.255 a 0
r1(config-router)#net 1.1.1.1 0.0.0.0 a 0
Enter configuration commands, one per line.  End with CNTL/Z.
r1(config)#int lo 0
r1(config-if)#ip ospf net point-to-point
 
 
 
r2(config)#router ospf 1
r2(config-router)#router-id 2.2.2.2
r2(config-router)#net 12.1.1.0 0.0.0.255 a 0
r2(config-router)#net 2.2.2.2 0.0.0
*Mar  1 00:08:13.799: %OSPF-5-ADJCHG: Process 1, Nbr 1.1.1.1 on Serial1/0 from LOADING to FULL, Loading Done
r2(config-router)#net 2.2.2.2 0.0.0.0  a 0
r2(config-router)#int lo 0
r2(config-if)#int lo 0
r2(config-if)#ip ospf network point-to-point
 
 
此时在R1上r1#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
 
     1.0.0.0/32 is subnetted, 1 subnets
C       1.1.1.1 is directly connected, Loopback0
     2.0.0.0/32 is subnetted, 1 subnets
O       2.2.2.2 [110/65] via 12.1.1.2, 00:02:48, Serial1/0
     12.0.0.0/24 is subnetted, 1 subnets
C       12.1.1.0 is directly connected, Serial1/0
r1#ping 2.2.2.2 source lo 0
 
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 2.2.2.2, timeout is 2 seconds:
Packet sent with a source address of 1.1.1.1 
!!!!!      ping通,我们就可以起BGP
Success rate is 100 percent (5/5), round-trip min/avg/max = 8/19/4
 
 
r1(config)#router bgp 12
r1(config-router)#bgp router-id 1.1.1.1
r1(config-router)#neighbor 2.2.2.2 remote-as 12
 

r2(config)#router bgp 12
r2(config-router)#bgp router-id 2.2.2.2
r2(config-router)#neighbor 1.1.1.1 remote-as 12
 
此时R1show ip route 
r1#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
 
     1.0.0.0/32 is subnetted, 1 subnets
C       1.1.1.1 is directly connected, Loopback0
     2.0.0.0/32 is subnetted, 1 subnets
O       2.2.2.2 [110/65] via 12.1.1.2, 00:08:51, Serial1/0
     12.0.0.0/24 is subnetted, 1 subnets
C       12.1.1.0 is directly connected, Serial1/0
发现R1去往R2的12.1.1.2 会以自身s1/0为逃出接口
 
r1#show ip int bri
Interface                  IP-Address      OK? Method Status                Protocol
Ethernet0/0                unassigned      YES unset  administratively down down    
Ethernet0/1                unassigned      YES unset  administratively down down    
Ethernet0/2                unassigned      YES unset  administratively down down    
Ethernet0/3                unassigned      YES unset  administratively down down    
Serial1/0                  12.1.1.1        YES manual up                    up      
Serial1/1                  unassigned      YES unset  administratively down down    
Serial1/2                  unassigned      YES unset  administratively down down    
Serial1/3                  unassigned      YES unset  administratively down down    
Loopback0                  1.1.1.1         YES manual up                    up      
会发现s1/0的IP正好是12.1.1.1
也可以通过debug ip packet 发现源和目的
r1#debug ip packet
IP packet debugging is on
r1#
*Mar  1 00:20:24.271: IP:  s=12.1.1.1 (local), d=224.0.0.5 (Serial1/0), len 80, sending broad/multicast
r1#
*Mar  1 00:20:27.979: IP: s=12.1.1.2 (Serial1/0), d=224.0.0.5, len 80, rcvd 0
r1#
*Mar  1 00:20:34.271: IP: s=12.1.1.1 (local), d=224.0.0.5 (Serial1/0), len 80, sending broad/multicast
r1#
*Mar  1 00:20:37.971: IP: s=12.1.1.2 (Serial1/0), d=224.0.0.5, len 80, rcvd 0
r1# 
*Mar  1 00:20:44.271: IP: s=12.1.1.1 (local), d=224.0.0.5 (Serial1/0), len 80, sending broad/multicast
r1#
*Mar  1 00:20:47.979: IP: s=12.1.1.2 (Serial1/0), d=224.0.0.5, len 80, rcvd 0
r1#
* Mar  1 00:20:51.291: IP: tableid=0, s=12.1.1.1 (local), d=2.2.2.2 (Serial1/0), routed via FIB
*Mar  1 00:20:51.359: IP: tableid=0, s=2.2.2.2 (Serial1/0), d=12.1.1.1 (Serial1/0), routed via RIB
*Mar  1 00:20:51.359: IP: s=2.2.2.2 (Serial1/0), d=12.1.1.1 (Serial1/0), len 40, rcvd 3
r1#debug ip bgp
BGP debugging is on for address family: BGP IPv4
r1#
r1#
r1#
r1#clear ip bgp * soft
r1#
r1#
r1#
*Mar  1 00:24:01.015: BGPNSF state: 2.2.2.2 went from nsf_not_active to nsf_not_active
*Mar  1 00:24:01.015: BGP: 2.2.2.2 went from Active to Idle
*Mar  1 00:24:01.015: BGP: 2.2.2.2 went from Idle to Active
*Mar  1 00:24:01.019: BGP: 2.2.2.2 open active, delay 8039ms
r1#
*Mar  1 00:24:09.059: BGP: 2.2.2.2 open active, local address 12.1.1.1  在建立BGP连接时是以自身12.1.1.1为源的
*Mar  1 00:24:09.111: BGP: 2.2.2.2 open failed: Connection refused by remote host
r1#unde all
All possible debugging has been turned off
r1#show ip bgp nei 2.2.2.2
BGP neighbor is 2.2.2.2,  remote AS 12, internal link
  BGP version 4, remote router ID 0.0.0.0
  BGP state = Active
  Last read 00:03:31, hold time is 180, keepalive interval is 60 seconds
  Message statistics:
    InQ depth is 0
    OutQ depth is 0
                         Sent       Rcvd
    Opens:                  0          0
    Notifications:          0          0
    Updates:                0          0
    Keepalives:             0          0
    Route Refresh:          0          0
    Total:                  0          0
  Default minimum time between advertisement runs is 5 seconds
 
 For address family: BGP IPv4
  BGP table version 1, neighbor version 0/0
 Output queue size : 0
  Index 1, Offset 0, Mask 0x2
  1 update-group member
                                 Sent       Rcvd
  Prefix activity:               ----       ----
    Prefixes Current:               0          0
    Prefixes Total:                 0          0
    Implicit Withdraw:              0          0
    Explicit Withdraw:              0          0
    Used as bestpath:             n/a          0
    Used as multipath:            n/a          0
          
                                   Outbound    Inbound
  Local Policy Denied Prefixes:    --------    -------
    Total:                                0          0
  Number of NLRIs in the update sent: max 0, min 0
          
  Connections established 0; dropped 0
  Last reset never
  No active TCP connection  此时R1R2之间TCP根本就没连接起来,为什么??
因为刚才反复强调要满足交叉相同原则,即一个目的IP是对端的源IP,而R1的源12.1.1.1 目的2.2.2.2
而R2的源是12.1.1.2 目的是1.1.1.1 四个IP皆不同,如何建立TCP,所以 我们要将R1R2的源目的改成满足
交叉相同即用自身环回口作为源   R1的源1.1.1.1 目的2.2.2.2   R2的源2.2.2.2 目的1.1.1.1
r1(config)#router bgp 12
r1(config-router)#neighbor 2.2.2.2 update-source lo 0
 
r2(config)#router bgp 12
r2(config-router)#neighbor 1.1.1.1 update-source lo 0
此时通过LO 0来建立TCP对等体会话,,而且使用的是IGP负载均衡
 
r1(config)#int e0/0
r1(config-if)#ip add 10.1.1.1 255.255.255.0
r1(config-if)#no shu
r1(config-if)#
*Mar  1 00:45:49.795: %LINK-3-UPDOWN: Interface Ethernet0/0, changed state to up
*Mar  1 00:45:50.795: %LINEPROTO-5-UPDOWN: Line protocol on Interface Ethernet0/0, changed state to up
r1(config-if)#do show ip bgp summary
BGP router identifier 1.1.1.1, local AS number 12
BGP table version is 1, main routing table version 1
 
Neighbor        V    AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
2.2.2.2         4    12       7       7        0    0    0 00:04:26 
此时的BGP已连接起来
此时将以太口换回口全部建立OSPF中
 
 
r1(config)#router ospf 1
r1(config-router)#net 10.1.1.0 0.0.0.255 a 0
r1(config-router)#net 1.1.1.1 0.0.0.0 a 0
r1(config-router)#net 12.1.1.0 0.0.0.255 a 0
r1(config-router)#end
r1#
*Mar  1 00:49:42.571: %SYS-5-CONFIG_I: Configured from console by console
r1#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
r1(config)#int e0/0
r1(config-if)#ip ospf cost 64  将以太链路的开销值改为与串口开销值相同
 
 
r2(config)#router ospf 1
r2(config-router)#net 12.1.1.0 0.0.0.255 a 0
r2(config-router)#net 10.1.1.0 0.0.0.255 a 0
r2(config-router)#
r2(config-router)#net 2.2.2.2 0.0.0.0 a 0
r2(config-router)#
r2(config-router)#end
r2(config)#int e0/0
r2(config-if)#ip ospf cost 64
 
 
 
此时r1#show ip ospf nei
 
Neighbor ID     Pri   State           Dead Time   Address         Interface
2.2.2.2           1   FULL/BDR        00:00:34     10.1.1.2        Ethernet0/0
2.2.2.2           0   FULL/  -        00:00:39     12.1.1.2        Serial1/0     发现R1有2条路径到达2.2.2.2在
建立BGP是变相使用IGP
 
r2#show ip ospf nei
 
Neighbor ID     Pri   State           Dead Time   Address         Interface
1.1.1.1           1   FULL/DR         00:00:39    10.1.1.1        Ethernet0/0
1.1.1.1           0   FULL/  -        00:00:34    12.1.1.1        Serial1/0
 
实验完成,在建立IBGP对等体时多用环回口【默认直连】,在EBGP时也可用换回口,修改TTL
值,否则BGP一直卡在idle状态,OPEN包不可达
设置EBGP多跳的概念
 
关于BGP的小实验1 - sonysony12345 - sonysony12345的博客
添加R3后的基本配置
r2#show ip int bri
Interface                  IP-Address      OK? Method Status                Protocol
Ethernet0/0                10.1.1.2        YES NVRAM  up                    up      
Ethernet0/1                unassigned      YES NVRAM  administratively down down    
Ethernet0/2                unassigned      YES NVRAM  administratively down down    
Ethernet0/3                unassigned      YES NVRAM  administratively down down    
Serial1/0                  12.1.1.2        YES NVRAM  up                    up      
Serial1/1                  23.1.1.2        YES NVRAM  up                    up      
Serial1/2                  unassigned      YES NVRAM  administratively down down    
Serial1/3                  unassigned      YES NVRAM  administratively down down    
Loopback0                  2.2.2.2         YES NVRAM  up                    up  
 
 
 
 
 
r3#show ip int bri
Interface                  IP-Address      OK? Method Status                Protocol
Ethernet0/0                unassigned      YES NVRAM  administratively down down    
Ethernet0/1                unassigned      YES NVRAM  administratively down down    
Ethernet0/2                unassigned      YES NVRAM  administratively down down    
Ethernet0/3                unassigned      YES NVRAM  administratively down down    
Serial1/0                  23.1.1.3        YES NVRAM  up                    up      
Serial1/1                  unassigned      YES NVRAM  up                    down    
Serial1/2                  unassigned      YES NVRAM  administratively down down    
Serial1/3                  unassigned      YES NVRAM  administratively down down    
Loopback0                  3.3.3.3         YES NVRAM  up                    up      
r3(config)#router bgp 3
r3(config-router)#bgp router-id 3.3.3.3
r3(config-router)#neighbor 2.2.2.2 remote-as 12
r3(config-router)#neighbor 2.2.2.2 up lo 0
r3(config-router)#end
Mar  1 00:44:51.751: %SYS-5-CONFIG_I: Configured from console by console
r3#show ip ospf nei
 
Neighbor ID     Pri   State           Dead Time   Address         Interface
2.2.2.2           0   FULL/  -        00:00:35    23.1.1.2        Serial1/0
r3#show ip bgp summary
BGP router identifier 3.3.3.3, local AS number 3
BGP table version is 1, main routing table version 1
 
Neighbor        V    AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
2.2.2.2         4    12       0       0        0    0    0 never     Idle   处于IDLE状态
,最多10秒.BGP最多用1分钟也会起来『30+20+10』,一直没起来是卡在3层IP寻址有问题,设置TTL值
使之比原先要大一些即可
r3#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
r3(config)#router bgp 3
r3(config-router)#nei 2.2.2.2 ebgp-multihop
r3(config-router)#end
 
 
r2(config)#router bgp 12
r2(config-router)#neighbor 3.3.3.3  ebgp-multihop
r2(config-router)#end
r2#sh
*Mar  1 00:52:05.403: %SYS-5-CONFIG_I: Configured from console by console
r2#show ip bgp
 
r2#
r2#
r2#show ip bgp summary
BGP router identifier 2.2.2.2, local AS number 12
BGP table version is 1, main routing table version 1
 
Neighbor        V    AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
1.1.1.1         4    12      54      54        0    0    0 00:51:44        0
3.3.3.3         4     3       0       0        0    0    0 never     Active
r2#
r2#
*Mar  1 00:52:36.335: %BGP-5-ADJCHANGE: neighbor 3.3.3.3 Up 
 
 
 
r3(config)#router bgp 3
r3(config-router)#nei 2.2.2.2 ebgp-multihop
r3(config-router)#end
r3#
*Mar  1 00:50:33.995: %SYS-5-CONFIG_I: Configured from console by console
r3#
r3#show ip bgp summary
BGP router identifier 3.3.3.3, local AS number 3
BGP table version is 1, main routing table version 1
 
Neighbor        V    AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
2.2.2.2         4    12       0       0        0    0    0 never    Active
r3#
r3#show ip bgp summary
BGP router identifier 3.3.3.3, local AS number 3
BGP table version is 1, main routing table version 1
 
Neighbor        V    AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
2.2.2.2         4    12       0       0        0    0    0 never     Active
r3#show ip bgp summary
BGP router identifier 3.3.3.3, local AS number 3
BGP table version is 1, main routing table version 1
 
Neighbor        V    AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
2.2.2.2         4    12       4       4        0    0    0 00:01:27        0
r3#show ip bgp summary
BGP router identifier 3.3.3.3, local AS number 3
BGP table version is 1, main routing table version 1
 
Neighbor        V    AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
2.2.2.2         4    12       4       4        0    0    0 00:01:30        0  ----已经起来了