Cisco配置BGP

拓扑图如下所示

路由器的基本配置

R1

sh 复制代码
R1#configure terminal 
R1(config)#interface e0/0
R1(config-if)#ip add 10.1.12.1 255.255.255.0
R1(config-if)#no shutdown 

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

R2

sh 复制代码
R2(config)#interface e0/0
R2(config-if)#ip address 10.1.12.2 255.255.255.0
R2(config-if)#no shutdown 

R2(config-if)#interface e0/1
R2(config-if)#ip address 10.1.23.2 255.255.255.0
R2(config-if)#no shutdown

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

R3

sh 复制代码
R3(config)#interface e0/0
R3(config-if)#ip address 10.1.23.3 255.255.255.0
R3(config-if)#no shutdown 

R3(config-if)#interface e0/1
R3(config-if)#ip address 10.1.34.3 255.255.255.0
R3(config-if)#no shutdown 

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

R4

sh 复制代码
Router(config)#interface e0/0
Router(config-if)#ip address 10.1.34.4 255.255.255.0
Router(config-if)#no shutdown 

Router(config-if)#interface lo0
Router(config-if)#ip address 4.4.4.4 255.255.255.0
Router(config-if)#no shutdown

配置BGP

配置BGP邻居,我们使用直连建立BGP邻居关系,但是这种方式有缺点,当接口挂了以后BGP邻居就挂了。 比较好的方式是跑一个IGP路由协议,然后使用loopback接口进行邻居的建立。

R1

sh 复制代码
R1(config)#router bgp 123 

R1(config-router)#neighbor 10.1.12.2 remote-as 123

R2

sh 复制代码
R2(config)#router bgp 123
R2(config-router)#neighbor 10.1.12.1 remote-as 123
R2(config-router)#neighbor 10.1.23.3 remote-as 123

R3

sh 复制代码
R3(config)#router bgp 123
R3(config-router)#neighbor 10.1.23.2 remote-as 123
R3(config-router)#neighbor 10.1.34.4 remote-as 400

R4

sh 复制代码
R4(config)#router bgp 400
R4(config-router)#neighbor 10.1.34.3 remote-as 123

配置完BGP后,我们可以查看下邻居关系是否正常建立

R2建立的邻居关系

sh 复制代码
R2#show ip bgp summary 
BGP router identifier 2.2.2.2, local AS number 123
BGP table version is 1, main routing table version 1

Neighbor        V           AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
10.1.12.1       4          123      13      13        1    0    0 00:08:55        0
10.1.23.3       4          123       8       6        1    0    0 00:04:22        0

R3建立的邻居关系

sh 复制代码
R3#show ip bgp summary 
BGP router identifier 3.3.3.3, local AS number 123
BGP table version is 1, main routing table version 1

Neighbor        V           AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
10.1.23.2       4          123       7       9        1    0    0 00:04:46        0
10.1.34.4       4          400       5       5        1    0    0 00:01:31        0

往BGP进行注入路由条目

在R4中配置

我们把4.4.4.0宣告进BGP

sh 复制代码
R4(config)#router bgp 400
R4(config-router)#network 4.4.4.0 mask 255.255.255.0

查看下R4的BGP路由表

sh 复制代码
R4#show ip bgp
BGP table version is 2, local router ID is 4.4.4.4
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, 
              t secondary path, 
Origin codes: i - IGP, e - EGP, ? - incomplete
RPKI validation codes: V valid, I invalid, N Not found

     Network          Next Hop            Metric LocPrf Weight Path
 *>   4.4.4.0/24       0.0.0.0                  0         32768 i

查看下R3的BGP路由表,可以看到学习到了R4通告的路由

sh 复制代码
R3#show 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, m multipath, b backup-path, f RT-Filter, 
              x best-external, a additional-path, c RIB-compressed, 
              t secondary path, 
Origin codes: i - IGP, e - EGP, ? - incomplete
RPKI validation codes: V valid, I invalid, N Not found

     Network          Next Hop            Metric LocPrf Weight Path
 *>   4.4.4.0/24       10.1.34.4                0             0 400 i

因为该BGP路由最优会被装载进R3的路由表中

sh 复制代码
R3#show ip route
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, p - overrides from PfR

Gateway of last resort is not set

      3.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C        3.3.3.0/24 is directly connected, Loopback0
L        3.3.3.3/32 is directly connected, Loopback0
      4.0.0.0/24 is subnetted, 1 subnets
B        4.4.4.0 [20/0] via 10.1.34.4, 00:06:26
      10.0.0.0/8 is variably subnetted, 4 subnets, 2 masks
C        10.1.23.0/24 is directly connected, Ethernet0/0
L        10.1.23.3/32 is directly connected, Ethernet0/0
C        10.1.34.0/24 is directly connected, Ethernet0/1
L        10.1.34.3/32 is directly connected, Ethernet0/1

在R3上ping一下4.4.4.4,可以ping通

sh 复制代码
R3#ping 4.4.4.4
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 4.4.4.4, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms

在R2上查看下bgp路由表,R3直接把下一跳的10.1.34.4路由发给了R2,但是R2到10.1.34.4不可达,R2此时ping不通4.4.4.4,同时R2也不会把这条路由传给它的bgp邻居。

sh 复制代码
R2#show ip bgp
BGP table version is 1, local router ID is 2.2.2.2
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, 
              t secondary path, 
Origin codes: i - IGP, e - EGP, ? - incomplete
RPKI validation codes: V valid, I invalid, N Not found

     Network          Next Hop            Metric LocPrf Weight Path
 * i  4.4.4.0/24       10.1.34.4                0    100      0 400 i

在R4上配置一条默认路由

sh 复制代码
R4(config)#ip route 0.0.0.0 0.0.0.0 10.1.34.3

在R3上把传给R2的BGP路由的下一跳指定为自己

sh 复制代码
R3(config)#router  bgp 123
R3(config-router)#neighbor 10.1.23.2 next-hop-self

查看R2的BGP路由

sh 复制代码
R2#show 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, 
              r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter, 
              x best-external, a additional-path, c RIB-compressed, 
              t secondary path, 
Origin codes: i - IGP, e - EGP, ? - incomplete
RPKI validation codes: V valid, I invalid, N Not found

     Network          Next Hop            Metric LocPrf Weight Path
 *>i  4.4.4.0/24       10.1.23.3                0    100      0 400 i

R2可以ping通4.4.4.4了

sh 复制代码
R2#ping 4.4.4.4
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 4.4.4.4, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/2 ms

R1的BGP路由表因为水平分割原因导致是空的,可以把R1和R3之间建立一个IBGP的邻居关系。

相关推荐
Gogo8161 天前
BigInt 与 Number 的爱恨情仇,为何大佬都劝你“能用 Number 就别用 BigInt”?
后端
fuquxiaoguang1 天前
深入浅出:使用MDC构建SpringBoot全链路请求追踪系统
java·spring boot·后端·调用链分析
毕设源码_廖学姐1 天前
计算机毕业设计springboot招聘系统网站 基于SpringBoot的在线人才对接平台 SpringBoot驱动的智能求职与招聘服务网
spring boot·后端·课程设计
野犬寒鸦1 天前
从零起步学习并发编程 || 第六章:ReentrantLock与synchronized 的辨析及运用
java·服务器·数据库·后端·学习·算法
逍遥德1 天前
如何学编程之01.理论篇.如何通过阅读代码来提高自己的编程能力?
前端·后端·程序人生·重构·软件构建·代码规范
MX_93591 天前
Spring的bean工厂后处理器和Bean后处理器
java·后端·spring
程序员泠零澪回家种桔子1 天前
Spring AI框架全方位详解
java·人工智能·后端·spring·ai·架构
源代码•宸1 天前
大厂技术岗面试之谈薪资
经验分享·后端·面试·职场和发展·golang·大厂·职级水平的薪资
晚霞的不甘1 天前
CANN 编译器深度解析:UB、L1 与 Global Memory 的协同调度机制
java·后端·spring·架构·音视频
喵叔哟1 天前
06-ASPNETCore-WebAPI开发
服务器·后端·c#