思科|实验|配置基本BGP

本文详细介绍了一种典型的BGP配置场景,包括启动BGP进程、配置通告网络、设置IBGP与EBGP邻居、配置BGP路由更新源及汇总等,并提供了详细的路由器配置示例与调试方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

实验目的

通过实验掌握:

  1. 启动BGP路由进程
  2. BGP进程中通告网络的方式
  3. IBGP和EBGP邻居配置
  4. BGP路由更新源和next-hop-self配置
  5. BGP路由汇总配置
  6. 对等体组配置
  7. BGP路由调试方法

实验拓扑

配置IBGP和EBGP实验拓扑

基本配置

根据拓扑信息配置网络接口

R1

Router>enable 
Router#configure terminal 
Router(config)#hostname R1

R1(config)#interface loopback 0
R1(config-if)#ip address 1.1.1.1 255.255.255.0
R1(config-if)#no shutdown 

R1(config)#interface ethernet 0/0
R1(config-if)#ip address 12.12.12.1 255.255.255.0
R1(config-if)#no shutdown 

R2

Router>enable 
Router#configure terminal 
Router(config)#hostname R2

R2(config)#interface loopback 0
R2(config-if)#ip address 2.2.2.2 255.255.255.0
R2(config-if)#no shutdown 

R2(config)#interface ethernet 0/0
R2(config-if)#ip address 12.12.12.2 255.255.255.0
R2(config-if)#no shutdown 

R2(config)#interface ethernet 0/1
R2(config-if)#ip address 23.23.23.2  255.255.255.0
R2(config-if)#no shutdown 

R3

Router>enable 
Router#configure terminal 
Router(config)#hostname R3

R3(config)#interface loopback 0
R3(config-if)#ip address 3.3.3.3 255.255.255.0
R3(config-if)#no shutdown 

R3(config)#interface ethernet 0/0
R3(config-if)#ip address 23.23.23.3 255.255.255.0
R3(config-if)#no shutdown 

R3(config)#interface ethernet 0/1
R3(config-if)#ip address 34.34.34.3 255.255.255.0
R3(config-if)#no shutdown 

R4

Router>enable 
Router#configure terminal 
Router(config)#hostname R4

R4(config)#interface loopback 0
R4(config-if)#ip address 4.4.0.4 255.255.255.0
R4(config-if)#no shutdown 

R4(config)#interface loopback 1
R4(config-if)#ip address 4.4.1.4 255.255.255.0
R4(config-if)#no shutdown 

R4(config)#interface loopback 2
R4(config-if)#ip address 4.4.2.4 255.255.255.0
R4(config-if)#no shutdown 

R4(config)#interface loopback 3
R4(config-if)#ip address 4.4.3.4 255.255.255.0
R4(config-if)#no shutdown 

R4(config)#interface ethernet 0/0
R4(config-if)#ip address 34.34.34.4 255.255.255.0
R4(config-if)#no shutdown 

配置路由

R1

//先配置AS 100的IGP
R1(config)#router eigrp 1
R1(config-router)#network 1.1.1.1 0.0.0.0
R1(config-router)#network 12.12.12.1 0.0.0.0 
R1(config-router)#exit 

//配置BGP
R1(config)#router bgp 100 //启动BGP进程 本路由 As 100
R1(config-router)#no synchronization //关闭同步,高版本IOS默认配置
R1(config-router)#bgp router-id 1.1.1.1 //配置BGP的router ID 

R1(config-router)#neighbor 2.2.2.2 remote-as 100 //宣告2.2.2.2 为邻居 他在AS100
R1(config-router)#neighbor 2.2.2.2 update-source loopback 0 //指定BGP更新源为loopback 0
R1(config-router)#neighbor 3.3.3.3 remote-as 100
R1(config-router)#neighbor 3.3.3.3 update-source loopback 0
R1(config-router)#network 1.1.1.0 mask 255.255.255.0 //宣告网络
R1(config-router)#no auto-summary //关闭自动汇总,高版本IOS默认配置

R2

R2(config)#router eigrp 1
R2(config-router)#network 2.2.2.2 0.0.0.0
R2(config-router)#network 12.12.12.2 0.0.0.0 
R2(config-router)#network 23.23.23.2 0.0.0.0 
R2(config-router)#exit 

R2(config)#router bgp 100
R2(config-router)#no synchronization 
R2(config-router)#bgp router-id 2.2.2.2

R2(config-router)#neighbor 1.1.1.1 remote-as 100 
R2(config-router)#neighbor 1.1.1.1 update-source loopback 0 
R2(config-router)#neighbor 3.3.3.3 remote-as 100 
R2(config-router)#neighbor 3.3.3.3 update-source loopback 0 

如果两台路由器配置了相同的BGP路由ID会重复出现下面报文
(我将R2的router-ID配置为1.1.1.1 收到的报文)
*Sep 19 16:37:44.807: %BGP-3-NOTIFICATION: sent to neighbor 1.1.1.1 passive 2/3 (BGP identifier wrong) 4 bytes 01010101
R2(config-router)#
*Sep 19 16:37:44.807: %BGP-4-MSGDUMP: unsupported or mal-formatted message received from 1.1.1.1:
FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF 0039 0104 0064 00B4 0101 0101 1C02 0601
0400 0100 0102 0280 0002 0202 0002 0246 0002 0641 0400 0000 64
R2(config-router)#
*Sep 19 16:37:49.634: %BGP-5-NBR_RESET: Neighbor 1.1.1.1 passive reset (BGP Notification sent)
*Sep 19 16:37:49.634: %BGP-5-ADJCHANGE: neighbor 1.1.1.1 passive Down BGP Notification sent

R3

R3(config)#router eigrp 1
R3(config-router)#network 3.3.3.3 0.0.0.0
R3(config-router)#network 23.23.23.3 0.0.0.0 


R3(config)#router bgp 100
R3(config-router)#no synchronization 
R3(config-router)#bgp router-id 3.3.3.3

R3(config-router)#neighbor 1.1.1.1 remote-as 100 //neihbor后面的地址是邻居更新源的地址
R3(config-router)#neighbor 1.1.1.1 update-source loopback 0 
R3(config-router)#neighbor 1.1.1.1 next-hop-self //配置下一条的更新源为自己,从EBGP学到的路由,再发给IBGP邻居时,会修改BGP更新源为自己.
R2(config-router)#neighbor 2.2.2.2 remote-as 100 
R3(config-router)#neighbor 2.2.2.2 update-source loopback 0 
R3(config-router)#neighbor 2.2.2.2 next-hop-self

R3(config-router)#neighbor 34.34.34.4 remote-as 200 //EBGP的邻居一般实验对端的接口地址而不是环回口

配置BGP邻居时 也可以通过对等体组(BGP的邻居)来实现,可以减少配置的工作量,替代配置如下:

R3(config-router)#neighbor Pretty peer-group  //创建一个叫Pretty的对等体组
//下面配置对等体的策略
R3(config-router)#neighbor Pretty remote-as 100 
R3(config-router)#neighbor Pretty update-source Loopback 0
R3(config-router)#neighbor Pretty next-hop-self 
//加入对等体组
R3(config-router)#neighbor 1.1.1.1 peer-group Pretty 
R3(config-router)#neighbor 2.2.2.2 peer-group Pretty 

可以通过命令show ip bgp peer-group查看对等体组的信息:

R3#show ip bgp peer-group
BGP peer-group is Pretty,  remote AS 100 //对等体组及AS号
  BGP version 4
  Neighbor sessions:
    0 active, is not multisession capable (disabled)
  Default minimum time between advertisement runs is 0 seconds

 For address family: IPv4 Unicast //地址族
  BGP neighbor is Pretty, peer-group internal, members: //对等体成员
  1.1.1.1 2.2.2.2 
  Index 0, Advertise bit 0
  NEXT_HOP is always this router for eBGP paths // 下一条一直是本路由
  Interface associated: (none)
  Update messages formatted 0, replicated 0
  Number of NLRIs in the update sent: max 0, min 0

R4


R4(config)#ip route 4.4.0.0 255.255.252.0 null 0
R4(config)#router bgp 200
R4(config-router)#bgp router-id 4.4.4.4

R4(config-router)#neighbor 34.34.34.3 remote-as 100
*Sep 19 17:15:07.931: %BGP-5-ADJCHANGE: neighbor 34.34.34.3 Up //与34.34.34.3邻居建立成功


R4(config-router)#network 4.4.0.0 mask 255.255.255.0
R4(config-router)#network 4.4.1.0 mask 255.255.255.0
R4(config-router)#network 4.4.2.0 mask 255.255.255.0
R4(config-router)#network 4.4.3.0 mask 255.255.255.0

R4(config-router)#network 4.4.0.0 mask 255.255.252.0
//用network命令进行路由汇总通告,做这条配置是为了说明在BGP中,
//network命令不仅可以通告直连路由,还可以通告IGP路由表中的其他路由条目
//从功能上讲,该条路由可以取代上面通告的四条子网路由。
//本实验中汇总和明细路由都被通告,实际应用中不需要

每个路由器只能启动一个bgp进程,当启动多个进程时系统会报错:

R3(config)#router bgp 500
BGP is already running; AS is 100

实验调试

查看TCP链接信息摘要

R3#show tcp brief 
TCB       Local Address               Foreign Address             (state)
C2B45790  3.3.3.3.179                1.1.1.1.49748               ESTAB
C37B6560  3.3.3.3.179                2.2.2.2.33039               ESTAB
C2B441D0  34.34.34.3.179             34.34.34.4.51074            ESTAB

查看BGP的详细信息

R3#show ip bgp neighbors 34.34.34.4
BGP neighbor is 34.34.34.4,  remote AS 200, external link
//BGP的邻居地址和所在的AS external表示EBGP
  BGP version 4, remote router ID 4.4.4.4
  BGP state = Established, up for 00:11:25 //Established表示已经与邻居建立链接
  Last read 00:00:21, last write 00:00:38, hold time is 180, keepalive interval is 60 seconds
  Neighbor sessions:						//默认保持时间				//keepalive的发送周期
//后面的部分省略

可以通过命令修改keepalive 时间

R3(config-router)#timers bgp 66 188 //66是keepalive时间 188是Holdtime

也可以只修改单个邻居的时间

R3(config-router)#neighbor 2.2.2.2 timers 66 188

查看BGP的摘要信息

R3#show ip bgp summary 
BGP router identifier 3.3.3.3, local AS number 100 //BGP路由ID和本地AS
BGP table version is 6, main routing table version 6
//BGP表的版本号(BGP表变化时该号会+1)和注入主路由表的最后版本号
5 network entries using 700 bytes of memory
5 path entries using 400 bytes of memory
2/2 BGP path/bestpath attribute entries using 288 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 1412 total bytes of memory
//以上是BGP使用的内存情况
BGP activity 5/0 prefixes, 5/0 paths, scan interval 60 secs
//BGP的活动前缀,路径和扫描间隔
Neighbor        V           AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
1.1.1.1         4          100      29      30        6    0    0 00:23:53        1
2.2.2.2         4          100      28      29        6    0    0 00:23:52        0
34.34.34.4      4          200      30      30        6    0    0 00:23:56        4

邻居表的各个字段含义如下:

  • Neighbor : BGP邻居的路由器ID
  • V : BGP的版本号
  • AS : 邻居所在的AS号
  • MsgRcvd : 接收的BGP数据包的数量
  • MsgSent : 发送的BGP数据包数量
  • TblVer : 发送给该邻居的最后一个BGP表的版本号
  • InQ : 入站队列中等待处理的数据包的数量
  • OutQ : 出站队列中等待处理的数据包的数量
  • Up/Down : 保持邻居关系的时间
  • State/PfxRcd : BGP的连接状态或者收到的路由前缀数量

查看BGP表信息

R3#show ip bgp 
BGP table version is 6, local router ID is 3.3.3.3 //BGP表的版本号和路由器的BGP路由器ID
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal, 
              r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter, 
              x best-external, a additional-path, c RIB-compressed, 
//上面是BGP的不同状态
Origin codes: i - IGP, e - EGP, ? - incomplete 
//BGP路由的不同的起源和对应的代码
RPKI validation codes: V valid, I invalid, N Not found

     Network          Next Hop            Metric LocPrf Weight Path
 r>i 1.1.1.0/24       1.1.1.1                  0    100      0 i
 *>  4.4.0.0/22       34.34.34.4               0             0 200 i
 *>  4.4.1.0/24       34.34.34.4               0             0 200 i
 *>  4.4.2.0/24       34.34.34.4               0             0 200 i
 *>  4.4.3.0/24       34.34.34.4               0             0 200 i

Status codes对于含义如下:

  • s : 表示路由条目被抑制
  • d : 表示路由条目被惩罚而受到抑制,从而阻止不稳定的路由的发布
  • h : 表示该路由正在被惩罚,但还没有达到抑制的阈值而使他被抑制
  • * : 表示该路由条目有效
  • > : 表示该路由条目最优,可以被传递,达到最优的重要条件是下一跳可达
  • i : 表示该路由是从IBGP学到的
  • S : 表示该路由条目已经过期,用于支持NSF的路由器中
  • r : 表示将BGP表中的路由条目安装到IP表中失败,可以通过 show ip bgp rib-fsilure 显示没有安装到路由表的BGP路由以及没有装入的原因,如下
R3#show ip bgp rib-failure 
  Network            Next Hop                      RIB-failure   RIB-NH Matches
1.1.1.0/24         1.1.1.1             Higher admin distance              n/a
//路由条目没有被安装到路由表的原因是管理距离大
//因为EIGRP学到的该路由管理距离为90,而通过IBGP学到的路由的管理距离为200

查看路由表

R1#show ip route bgp 
Codes: L - local, 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, H - NHRP, l - LISP
       a - application route
       + - replicated route, % - next hop override

Gateway of last resort is not set

      4.0.0.0/8 is variably subnetted, 4 subnets, 2 masks
B        4.4.0.0/22 [200/0] via 3.3.3.3, 01:16:49
B        4.4.1.0/24 [200/0] via 3.3.3.3, 01:16:49
B        4.4.2.0/24 [200/0] via 3.3.3.3, 01:16:49
B        4.4.3.0/24 [200/0] via 3.3.3.3, 01:16:49
// 因为R3配置了next-hop-self 所有在R1看到的外部路由更新源为3.3.3.3  这里也能看到IBGP的管理距离为200
R1#
R3#show ip route bgp 
// code部分省略
Gateway of last resort is not set

      4.0.0.0/8 is variably subnetted, 4 subnets, 2 masks
B        4.4.0.0/22 [20/0] via 34.34.34.4, 01:18:37
B        4.4.1.0/24 [20/0] via 34.34.34.4, 01:18:37
B        4.4.2.0/24 [20/0] via 34.34.34.4, 01:18:37
B        4.4.3.0/24 [20/0] via 34.34.34.4, 01:18:37
//EBGP的管理距离为20

用ping命令测试

R4#ping 1.1.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 1.1.1.1, timeout is 2 seconds:
.....
Success rate is 0 percent (0/5)
// 直接ping是不通的 因为R1和R2没有到34.34.34.0的路由.
R4#ping 1.1.1.1 source 4.4.3.4  
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 1.1.1.1, timeout is 2 seconds:
Packet sent with a source address of 4.4.3.4 
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms
// 这里通了因为R1和R2里面有到4.4.3.0的路由.(show ip route 可以查看路由)
R4#
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值