华为BGP基础配置

BGP(Border Gateway Protocol)被称作边界网关协议,是一种运行于TCP上的唯一一种能够处理Internet网络的协议,也是唯一一种可以完善无关路由域之间的多路连接协议,属于外部路由协议。简单理解BGP就是第三方电信运营商通过技术手段,实现不同运营商可以共同访问一个IP,并且不同运营商之间都能达到最快的接入速度的技术。由于不同运营商(电信 联通 移动都有自己的AS域)之间访问彼此资源时会非常慢,在这种情况下BGP的作用就凸显出来。

从功能上讲BGP是一种自治系统间的动态路由协议。在一定程度上解决了各大运营商之间的网络穿透问题,它是直接将其中一条线路的IP映射到其他线路IP上,用BGP协议实现的单IP双线路或者多线路的效果。当用户浏览网站时,BGP会自动根据实际情况选择访问速度最优最快的路由,通过这种智能手段,各个运营商的用户都能达到最佳的访问速度,提高了用户的访问体验。

转载请注明以下内容:

来源:https://blog.csdn.net/annita2019/article/details/125787678

一、基本配置

先根据拓扑图把基础的IP地址添加好。

[Huawei]sy ar1
[ar1]in g0/0/0
[ar1-GigabitEthernet0/0/0]ip add 12.1.1.1 24
[ar1-GigabitEthernet0/0/0]q
[ar1]int lo 
[ar1]int LoopBack 0
[ar1-LoopBack0]ip add 1.1.1.1 32
[ar1-LoopBack0]q


[Huawei]sy ar2
[ar2]in g0/0/0
[ar2-GigabitEthernet0/0/0]ip add 12.1.1.2 24
[ar2-GigabitEthernet0/0/0]q
[ar2]in g0/0/1
[ar2-GigabitEthernet0/0/0]ip add 23.1.1.2 24
[ar2-GigabitEthernet0/0/0]q
[ar2]int lo 
[ar2]int LoopBack 0
[ar2-LoopBack0]ip add 2.2.2.2 32
[ar2-LoopBack0]q


[Huawei]sy ar3
[ar3]in g0/0/0
[ar3-GigabitEthernet0/0/0]ip add 34.1.1.3 24
[ar3-GigabitEthernet0/0/0]q
[ar3]in g0/0/1
[ar3-GigabitEthernet0/0/0]ip add 23.1.1.3 24
[ar3-GigabitEthernet0/0/0]q
[ar3]int lo 
[ar3]int LoopBack 0
[ar3-LoopBack0]ip add 3.3.3.3 32
[ar3-LoopBack0]q

[Huawei]sy ar4
[ar4]in g0/0/0
[ar4-GigabitEthernet0/0/0]ip add 34.1.1.4 24
[ar4-GigabitEthernet0/0/0]q
[ar4]int lo 
[ar4]int LoopBack 0
[ar4-LoopBack0]ip add 4.4.4.4 32
[ar4-LoopBack0]q

二、区域as200内的OSPF


AR2

[ar2]ospf router-id 2.2.2.2
[ar2-ospf-1]area 0
[ar2-ospf-1-area-0.0.0.0]network 2.2.2.2 0.0.0.0
[ar2-ospf-1-area-0.0.0.0]network 23.1.1.0 0.0.0.255 
注意:这里不需要宣告12.1.1.0

AR3

[ar3]ospf router-id 3.3.3.3
[ar3-ospf-1]area 0
[ar3-ospf-1-area-0.0.0.0]network 3.3.3.3 0.0.0.0
[ar3-ospf-1-area-0.0.0.0]network 23.1.1.0 0.0.0.255 
[ar3-ospf-1-area-0.0.0.0] network 34.1.1.0 0.0.0.255


AR4
[ar4]ospf router-id 4.4.4.4
[ar4-ospf-1]area 0
[ar4-ospf-1-area-0.0.0.0]net 34.1.1.0 0.0.0.255
[ar4-ospf-1-area-0.0.0.0]net 4.4.4.4 0.0.0.0
[ar4-ospf-1-area-0.0.0.0]q

三、BGP的配置

1、建立邻居

  • R1、R2建立EBGP

  • R2、R3、R4之间建立IBGP

[ar1]bgp 100
[ar1-bgp]peer 12.1.1.2 as-number 200

[ar2]bgp 200
[ar2-bgp]peer 12.1.1.1 as-number 100
[ar2-bgp]peer 3.3.3.3 as-number 200 
[ar2-bgp]peer 3.3.3.3 connect-interface LoopBack0
[ar2-bgp]peer 3.3.3.3 next-hop-local    #将到达3.3.3.3的源地址改为2.2.2.2
[ar2-bgp]q

[ar3]bgp 200
[ar3-bgp]peer 2.2.2.2 as-number 200 
[ar3-bgp]peer 2.2.2.2 connect-interface LoopBack0
[ar3-bgp]peer 4.4.4.4 as-number 200 
[ar3-bgp]peer 4.4.4.4 connect-interface LoopBack0

[ar4]bgp 200
[ar4-bgp]peer 3.3.3.3 as-number 200 
[ar4-bgp]peer 3.3.3.3 connect-interface LoopBack0
[ar4-bgp]q

注意:EBGP邻居只能使用物理接口,不能使用1.1.1.1的loopback接口

验证:

2、传递路由

就是把设备中已经存在的路由引入到BGP路由器中,也可以理解为调用。

引入方式:

  • network,单独引入

  • import-route,全部引入

  • 聚合路由/汇总路由

注意事项:在引入路由时,必须和路由表中的路由完全一样,不得修改字掩码

[ar2-bgp]dis ip rou
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
         Destinations : 15       Routes : 15       

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

        1.1.1.1/32  EBGP    255  0           D   12.1.1.1        GigabitEthernet0/0/0
        2.2.2.2/32  Direct  0    0           D   127.0.0.1       LoopBack0
        3.3.3.3/32  OSPF    10   1           D   23.1.1.3        GigabitEthernet0/0/1
        4.4.4.4/32  OSPF    10   2           D   23.1.1.3        GigabitEthernet0/0/1
       12.1.1.0/24  Direct  0    0           D   12.1.1.2        GigabitEthernet0/0/0
       12.1.1.2/32  Direct  0    0           D   127.0.0.1       GigabitEthernet0/0/0
     12.1.1.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet0/0/0
       23.1.1.0/24  Direct  0    0           D   23.1.1.2        GigabitEthernet0/0/1
       23.1.1.2/32  Direct  0    0           D   127.0.0.1       GigabitEthernet0/0/1
     23.1.1.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet0/0/1
       34.1.1.0/24  OSPF    10   2           D   23.1.1.3        GigabitEthernet0/0/1
      127.0.0.0/8   Direct  0    0           D   127.0.0.1       InLoopBack0
      127.0.0.1/32  Direct  0    0           D   127.0.0.1       InLoopBack0
127.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0
255.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0


[ar2-bgp]import-route ospf 1     #将所有OSPF路由引入BGP中

<ar2>dis bgp routing-table 

 BGP Local router ID is 2.2.2.2 
 Status codes: * - valid, > - best, d - damped,
               h - history,  i - internal, s - suppressed, S - Stale
               Origin : i - IGP, e - EGP, ? - incomplete


 Total Number of Routes: 6
      Network            NextHop        MED        LocPrf    PrefVal Path/Ogn

 *>   1.1.1.1/32         12.1.1.1        0                     0      100i
 *>   2.2.2.2/32         0.0.0.0         0                     0      ?
 *>   3.3.3.3/32         0.0.0.0         1                     0      ?
 *>   4.4.4.4/32         0.0.0.0         2                     0      ?
 *>   23.1.1.0/24        0.0.0.0         0                     0      ?
 *>   34.1.1.0/24        0.0.0.0         2                     0      ?

既然路由已经有了,我们就来测试一下连通性


<ar1>ping 2.2.2.2
  PING 2.2.2.2: 56  data bytes, press CTRL_C to break
    Reply from 2.2.2.2: bytes=56 Sequence=1 ttl=255 time=30 ms
    Reply from 2.2.2.2: bytes=56 Sequence=2 ttl=255 time=20 ms
    Reply from 2.2.2.2: bytes=56 Sequence=3 ttl=255 time=30 ms
    Reply from 2.2.2.2: bytes=56 Sequence=4 ttl=255 time=30 ms
    Reply from 2.2.2.2: bytes=56 Sequence=5 ttl=255 time=10 ms

  --- 2.2.2.2 ping statistics ---
    5 packet(s) transmitted
    5 packet(s) received
    0.00% packet loss
    round-trip min/avg/max = 10/24/30 ms

<ar1>ping 3.3.3.3
  PING 3.3.3.3: 56  data bytes, press CTRL_C to break
    Request time out
    Request time out
    Request time out
    Request time out
    Request time out

  --- 3.3.3.3 ping statistics ---
    5 packet(s) transmitted
    0 packet(s) received
    100.00% packet loss

<ar3>ping 1.1.1.1
  PING 1.1.1.1: 56  data bytes, press CTRL_C to break
    Reply from 1.1.1.1: bytes=56 Sequence=1 ttl=254 time=40 ms
    Reply from 1.1.1.1: bytes=56 Sequence=2 ttl=254 time=20 ms
    Reply from 1.1.1.1: bytes=56 Sequence=3 ttl=254 time=30 ms
    Reply from 1.1.1.1: bytes=56 Sequence=4 ttl=254 time=30 ms
    Reply from 1.1.1.1: bytes=56 Sequence=5 ttl=254 time=20 ms

  --- 1.1.1.1 ping statistics ---
    5 packet(s) transmitted
    5 packet(s) received
    0.00% packet loss
    round-trip min/avg/max = 20/28/40 ms


<ar1>ping 4.4.4.4
  PING 4.4.4.4: 56  data bytes, press CTRL_C to break
    Request time out
    Request time out
    Request time out
    Request time out
    Request time out

  --- 4.4.4.4 ping statistics ---
    5 packet(s) transmitted
    0 packet(s) received
    100.00% packet loss

<ar4>ping 1.1.1.1
  PING 1.1.1.1: 56  data bytes, press CTRL_C to break
    Request time out
    Request time out
    Request time out
    Request time out
    Request time out

  --- 1.1.1.1 ping statistics ---
    5 packet(s) transmitted
    0 packet(s) received
    100.00% packet loss

感觉不太靠谱,有通的,也有不通的。这个时候我们引入一个概念“BGP通告原则”

3、BGP通告原则

  • 仅将自己最优的路由发布给邻居

  • 通过EBGP获得的最优路由发布给所有BGP邻居

  • 通过IBGP获得的最优路由不会发布给其他的IBGP邻居

问题1:如果我们在AR2中不加这一条peer 3.3.3.3 next-hop-local,则AR3是无法ping通1.1.1.1的。

解决办法:就是将到达3.3.3.3的源地址改为2.2.2.2,因此就有了这一条peer 3.3.3.3 next-hop-local。但是这种方法在AR4中就无法使用了。因为我们看到上面第三条:“通过IBGP获得的最优路由不会发布给其他的IBGP邻居”,所以现在我们的AR4无法ping通1.1.1.1。

<ar4>dis bgp rou
空

因为bgp中我们所引入的OSPF路由,在AR4中是空的。所以AR4是没有学到任何BGP路由。

问题2:那么如何让AR4和AR1通信呢?

解决办法:在AR3上面做反射器。配置如下:

[ar3]bgp 200
[ar3-bgp]peer 4.4.4.4 re
[ar3-bgp]peer 4.4.4.4 reflect-client   #使4.4.4.4成为反射器的客户端
[ar3-bgp]dis th
[V200R003C00]
#
bgp 200
 peer 2.2.2.2 as-number 200 
 peer 2.2.2.2 connect-interface LoopBack0
 peer 4.4.4.4 as-number 200 
 peer 4.4.4.4 connect-interface LoopBack0
 #
 ipv4-family unicast
  undo synchronization
  peer 2.2.2.2 enable
  peer 4.4.4.4 enable
  peer 4.4.4.4 reflect-client
#
return
[ar3-bgp]

验证AR4的bgp路由:
<ar4>dis bgp rou

 BGP Local router ID is 4.4.4.4 
 Status codes: * - valid, > - best, d - damped,
               h - history,  i - internal, s - suppressed, S - Stale
               Origin : i - IGP, e - EGP, ? - incomplete


 Total Number of Routes: 5
      Network            NextHop        MED        LocPrf    PrefVal Path/Ogn

 *>i  1.1.1.1/32         2.2.2.2         0          100        0      100i
 *>i  3.3.3.3/32         2.2.2.2         1          100        0      ?
 *>i  4.4.4.4/32         2.2.2.2         2          100        0      ?
 *>i  23.1.1.0/24        2.2.2.2         0          100        0      ?
 *>i  34.1.1.0/24        2.2.2.2         2          100        0      ?

终于是通了,到时候无论有多少IBGP,只要这一条命令就搞定了。

验证:

<ar1>ping  -a 1.1.1.1 3.3.3.3
  PING 3.3.3.3: 56  data bytes, press CTRL_C to break
    Reply from 3.3.3.3: bytes=56 Sequence=1 ttl=254 time=50 ms
    Reply from 3.3.3.3: bytes=56 Sequence=2 ttl=254 time=20 ms
    Reply from 3.3.3.3: bytes=56 Sequence=3 ttl=254 time=40 ms
    Reply from 3.3.3.3: bytes=56 Sequence=4 ttl=254 time=30 ms
    Reply from 3.3.3.3: bytes=56 Sequence=5 ttl=254 time=40 ms

  --- 3.3.3.3 ping statistics ---
    5 packet(s) transmitted
    5 packet(s) received
    0.00% packet loss
    round-trip min/avg/max = 20/36/50 ms

<ar1>
<ar1>
<ar1>ping -a 1.1.1.1 4.4.4.4
  PING 4.4.4.4: 56  data bytes, press CTRL_C to break
    Reply from 4.4.4.4: bytes=56 Sequence=1 ttl=253 time=40 ms
    Reply from 4.4.4.4: bytes=56 Sequence=2 ttl=253 time=50 ms
    Reply from 4.4.4.4: bytes=56 Sequence=3 ttl=253 time=30 ms
    Reply from 4.4.4.4: bytes=56 Sequence=4 ttl=253 time=30 ms
    Reply from 4.4.4.4: bytes=56 Sequence=5 ttl=253 time=30 ms

  --- 4.4.4.4 ping statistics ---
    5 packet(s) transmitted
    5 packet(s) received
    0.00% packet loss
    round-trip min/avg/max = 30/36/50 ms

<ar1>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值