H3C BGP 基本配置实验
实验拓扑
 
实验需求
- 按照图示配置 IP 地址,R1 和 R5 上使用环回口模拟业务网段,R2,R3,R4 的环回口用于配置 Router-id 和建立 IBGP 邻居
- AS 200 运行 OSPF 实现内部网络互通
- R1,R2,R4,R5 运行 BGP,R1 和 R2 建立 EBGP 邻居,R4 和 R5 建立 EBGP 邻居,R2 和 R4 建立 IBGP 邻居。要求 EBGP 邻居使用直连接口建立邻居,IBGP 邻居使用环回口建立邻居
- R1 和 R5 把业务网段宣告进 BGP
- 在 R2 和 R4 上把 BGP 引入到 IGP 解决 BGP 路由黑洞问题
- 业务网段可以互通
实验步骤
设备IP地址配置
R1 IP地址配置
[R1]display ip interface brief 
*down: administratively down
(s): spoofing  (l): loopback
Interface           Physical Protocol IP address/Mask    VPN instance Description  
GE0/0               up       up       100.1.1.1/24       --           --
Loop0               up       up(s)    192.168.1.1/24     --           --
R2 IP地址配置
[R2]display ip interface brief 
*down: administratively down
(s): spoofing  (l): loopback
Interface           Physical Protocol IP address/Mask    VPN instance Description  
GE0/0               up       up       100.1.1.2/24       --           --
GE0/1               up       up       100.2.2.2/24       --           --
Loop0               up       up(s)    2.2.2.2/32         --           --
R3 IP地址配置
[R3]display ip interface brief 
*down: administratively down
(s): spoofing  (l): loopback
Interface           Physical Protocol IP address/Mask    VPN instance Description  
GE0/0               up       up       100.2.2.3/24       --           --
GE0/1               up       up       100.3.3.3/24       --           --
Loop0               up       up(s)    3.3.3.3/32         --           --
R4 IP地址配置
[R4]display ip interface brief 
*down: administratively down
(s): spoofing  (l): loopback
Interface           Physical Protocol IP address/Mask    VPN instance Description  
GE0/0               up       up       100.3.3.4/24       --           --
GE0/1               up       up       100.4.4.4/24       --           --
Loop0               up       up(s)    4.4.4.4/32         --           --
R5 IP地址配置
[R5]display ip interface brief 
*down: administratively down
(s): spoofing  (l): loopback
Interface           Physical Protocol IP address/Mask    VPN instance Description  
GE0/0               up       up       100.4.4.5/24       --           --
Loop0               up       up(s)    192.168.2.1/24     --           --
AS 200运行OSPF
R2 配置OSPF
#
ospf 1 router-id 2.2.2.2
 area 0.0.0.0
  network 2.2.2.2 0.0.0.0
  network 100.2.2.2 0.0.0.0
R3 配置OSPF
#
ospf 1 router-id 3.3.3.3
 area 0.0.0.0
  network 3.3.3.3 0.0.0.0
  network 100.2.2.3 0.0.0.0
  network 100.3.3.3 0.0.0.0
R4 配置OSPF
#
ospf 1 router-id 4.4.4.4
 area 0.0.0.0
  network 4.4.4.4 0.0.0.0
  network 100.3.3.4 0.0.0.0
BGP邻居建立
R1 和 R2 建立 EBGP 邻居
R1配置BGP与R2建立EBGP邻居
[R1]bgp 100  
[R1-bgp-default]peer 100.1.1.2 as-number 200
[R1-bgp-default]address-family ipv4 unicast 
[R1-bgp-default-ipv4]peer 100.1.1.2 enable
R2配置BGP与R1建立EBGP邻居
[R1]bgp 200  
[R1-bgp-default]peer 100.1.1.1 as-number 100
[R1-bgp-default]address-family ipv4 unicast 
[R1-bgp-default-ipv4]peer 100.1.1.1 enable
R2 和 R4 建立 IBGP 邻居
IBGP 邻居要求使用环回口建立,根据 BGP 邻居建立条件,需要修改 IBGP 邻居更新源为对应环回口
R2配置BGP与R4建立IBGP邻居
[R1]bgp 200  
[R1-bgp-default]peer 4.4.4.4 as-number 200
[R1-bgp-default]peer 4.4.4.4 connect-interface LoopBack0
[R1-bgp-default]address-family ipv4 unicast
[R1-bgp-default-ipv4]peer 4.4.4.4 enable
R4配置BGP与R2建立IBGP邻居
[R1]bgp 200  
[R1-bgp-default]peer 2.2.2.2 as-number 200
[R1-bgp-default]peer 2.2.2.2 connect-interface LoopBack0
[R1-bgp-default]address-family ipv4 unicast
[R1-bgp-default-ipv4]peer 2.2.2.2 enable
R4 和 R5 建立 EBGP 邻居
R4配置BGP与R5建立EBGP邻居
[R1]bgp 200  
[R1-bgp-default]peer 100.4.4.5 as-number 300
[R1-bgp-default]address-family ipv4 unicast 
[R1-bgp-default-ipv4]peer 100.4.4.5 enable
R5配置BGP与R4建立EBGP邻居
[R1]bgp 300  
[R1-bgp-default]peer 100.4.4.4 as-number 200
[R1-bgp-default]address-family ipv4 unicast 
[R1-bgp-default-ipv4]peer 100.4.4.4 enable
业务网段宣告进 BGP
在R1上将业务网段宣告进 BGP
[R1-bgp-default-ipv4]network 192.168.1.0 255.255.255.0
在R5上将业务网段宣告进 BGP
[R5-bgp-default-ipv4]network 192.168.2.0 255.255.255.0
修改 IBGP 邻居下一跳为本机
由于 R2 和 R4 既有 EBGP 邻居,又有 IBGP 邻居,为了使从 EBGP 邻居学习的路由传递至 IBGP 邻居时下一跳可达,需要修改 IBGP 邻居下一跳为本机
R2修改 IBGP 邻居下一跳为本机
[R2-bgp-default-ipv4]peer 4.4.4.4 next-hop-local
R4修改 IBGP 邻居下一跳为本机
[R2-bgp-default-ipv4]peer 2.2.2.2 next-hop-local
解决 BGP 路由黑洞问题
由于 R3 没有运行 BGP ,无法学习到业务网段路由,然而业务网段之间通讯的数据包会经过 R3 转发,所以造成 R3 上存在 BGP 路由黑洞
这里通过把 BGP 引入到 OSPF,使 R3 可以通过 OSPF 学习到业务网段的路由,来解决 BGP 路由黑洞问题
R2 BGP 引入到 OSPF
#
ospf 1 router-id 2.2.2.2
 import-route bgp
R4 BGP 引入到 OSPF
#
ospf 1 router-id 4.4.4.4
 import-route bgp
实验验证
业务网段是否可通
由于 BGP 只传递了业务网段路由,所以必须使用带源 PING,才能测试是否连通
[R1]ping 192.168.2.1
Ping 192.168.2.1 (192.168.2.1): 56 data bytes, press CTRL+C to break
Request time out
Request time out
Request time out
Request time out
Request time out
--- Ping statistics for 192.168.2.1 ---
5 packet(s) transmitted, 0 packet(s) received, 100.0% packet loss
[R1]%Mar  7 19:51:13:638 2024 R1 PING/6/PING_STATISTICS: Ping statistics for 192.168.2.1: 5 packet(s) transmitted, 0 packet(s) received, 100.0% packet loss.
[R1]ping -a 192.168.1.1 192.168.2.1
Ping 192.168.2.1 (192.168.2.1) from 192.168.1.1: 56 data bytes, press CTRL+C to break
56 bytes from 192.168.2.1: icmp_seq=0 ttl=252 time=2.505 ms
56 bytes from 192.168.2.1: icmp_seq=1 ttl=252 time=2.529 ms
56 bytes from 192.168.2.1: icmp_seq=2 ttl=252 time=2.519 ms
56 bytes from 192.168.2.1: icmp_seq=3 ttl=252 time=2.592 ms
56 bytes from 192.168.2.1: icmp_seq=4 ttl=252 time=1.770 ms
--- Ping statistics for 192.168.2.1 ---
5 packet(s) transmitted, 5 packet(s) received, 0.0% packet loss
round-trip min/avg/max/std-dev = 1.770/2.383/2.592/0.308 ms
[R1]%Mar  7 19:51:24:599 2024 R1 PING/6/PING_STATISTICS: Ping statistics for 192.168.2.1: 5 packet(s) transmitted, 5 packet(s) received, 0.0% packet loss, round-trip min/avg/max/std-dev = 1.770/2.383/2.592/0.308 ms.
拓展验证
BGP 引入到 OSPF前后对比情况
引入前
删除引入配置
[R2]ospf
[R2-ospf-1]undo import-route bgp 
[R4]ospf
[R4-ospf-1]undo import-route bgp
查询路由表
[R2]display ip routing-table 
Destinations : 19	Routes : 19
Destination/Mask   Proto   Pre Cost        NextHop         Interface
0.0.0.0/32         Direct  0   0           127.0.0.1       InLoop0
2.2.2.2/32         Direct  0   0           127.0.0.1       InLoop0
3.3.3.3/32         O_INTRA 10  1           100.2.2.3       GE0/1
4.4.4.4/32         O_INTRA 10  2           100.2.2.3       GE0/1
100.1.1.0/24       Direct  0   0           100.1.1.2       GE0/0
100.1.1.2/32       Direct  0   0           127.0.0.1       InLoop0
100.1.1.255/32     Direct  0   0           100.1.1.2       GE0/0
100.2.2.0/24       Direct  0   0           100.2.2.2       GE0/1
100.2.2.2/32       Direct  0   0           127.0.0.1       InLoop0
100.2.2.255/32     Direct  0   0           100.2.2.2       GE0/1
100.3.3.0/24       O_INTRA 10  2           100.2.2.3       GE0/1
127.0.0.0/8        Direct  0   0           127.0.0.1       InLoop0
127.0.0.1/32       Direct  0   0           127.0.0.1       InLoop0
127.255.255.255/32 Direct  0   0           127.0.0.1       InLoop0
192.168.1.0/24     BGP     255 0           100.1.1.1       GE0/0
192.168.2.0/24     BGP     255 0           4.4.4.4         GE0/1
224.0.0.0/4        Direct  0   0           0.0.0.0         NULL0
224.0.0.0/24       Direct  0   0           0.0.0.0         NULL0
255.255.255.255/32 Direct  0   0           127.0.0.1       InLoop0
[R3]display ip routing-table 
Destinations : 16	Routes : 16
Destination/Mask   Proto   Pre Cost        NextHop         Interface
0.0.0.0/32         Direct  0   0           127.0.0.1       InLoop0
2.2.2.2/32         O_INTRA 10  1           100.2.2.2       GE0/0
3.3.3.3/32         Direct  0   0           127.0.0.1       InLoop0
4.4.4.4/32         O_INTRA 10  1           100.3.3.4       GE0/1
100.2.2.0/24       Direct  0   0           100.2.2.3       GE0/0
100.2.2.3/32       Direct  0   0           127.0.0.1       InLoop0
100.2.2.255/32     Direct  0   0           100.2.2.3       GE0/0
100.3.3.0/24       Direct  0   0           100.3.3.3       GE0/1
100.3.3.3/32       Direct  0   0           127.0.0.1       InLoop0
100.3.3.255/32     Direct  0   0           100.3.3.3       GE0/1
127.0.0.0/8        Direct  0   0           127.0.0.1       InLoop0
127.0.0.1/32       Direct  0   0           127.0.0.1       InLoop0
127.255.255.255/32 Direct  0   0           127.0.0.1       InLoop0
224.0.0.0/4        Direct  0   0           0.0.0.0         NULL0
224.0.0.0/24       Direct  0   0           0.0.0.0         NULL0
255.255.255.255/32 Direct  0   0           127.0.0.1       InLoop0
[R4]display ip routing-table 
Destinations : 19	Routes : 19
Destination/Mask   Proto   Pre Cost        NextHop         Interface
0.0.0.0/32         Direct  0   0           127.0.0.1       InLoop0
2.2.2.2/32         O_INTRA 10  2           100.3.3.3       GE0/0
3.3.3.3/32         O_INTRA 10  1           100.3.3.3       GE0/0
4.4.4.4/32         Direct  0   0           127.0.0.1       InLoop0
100.2.2.0/24       O_INTRA 10  2           100.3.3.3       GE0/0
100.3.3.0/24       Direct  0   0           100.3.3.4       GE0/0
100.3.3.4/32       Direct  0   0           127.0.0.1       InLoop0
100.3.3.255/32     Direct  0   0           100.3.3.4       GE0/0
100.4.4.0/24       Direct  0   0           100.4.4.4       GE0/1
100.4.4.4/32       Direct  0   0           127.0.0.1       InLoop0
100.4.4.255/32     Direct  0   0           100.4.4.4       GE0/1
127.0.0.0/8        Direct  0   0           127.0.0.1       InLoop0
127.0.0.1/32       Direct  0   0           127.0.0.1       InLoop0
127.255.255.255/32 Direct  0   0           127.0.0.1       InLoop0
192.168.1.0/24     BGP     255 0           2.2.2.2         GE0/0
192.168.2.0/24     BGP     255 0           100.4.4.5       GE0/1
224.0.0.0/4        Direct  0   0           0.0.0.0         NULL0
224.0.0.0/24       Direct  0   0           0.0.0.0         NULL0
255.255.255.255/32 Direct  0   0           127.0.0.1       InLoop0
以上可以看到,在R3上没有去往业务网段的路由,所以目前是业务网段之间访问是不通的。
引入后
[R2]display ip routing-table 
Destinations : 19	Routes : 19
Destination/Mask   Proto   Pre Cost        NextHop         Interface
0.0.0.0/32         Direct  0   0           127.0.0.1       InLoop0
2.2.2.2/32         Direct  0   0           127.0.0.1       InLoop0
3.3.3.3/32         O_INTRA 10  1           100.2.2.3       GE0/1
4.4.4.4/32         O_INTRA 10  2           100.2.2.3       GE0/1
100.1.1.0/24       Direct  0   0           100.1.1.2       GE0/0
100.1.1.2/32       Direct  0   0           127.0.0.1       InLoop0
100.1.1.255/32     Direct  0   0           100.1.1.2       GE0/0
100.2.2.0/24       Direct  0   0           100.2.2.2       GE0/1
100.2.2.2/32       Direct  0   0           127.0.0.1       InLoop0
100.2.2.255/32     Direct  0   0           100.2.2.2       GE0/1
100.3.3.0/24       O_INTRA 10  2           100.2.2.3       GE0/1
127.0.0.0/8        Direct  0   0           127.0.0.1       InLoop0
127.0.0.1/32       Direct  0   0           127.0.0.1       InLoop0
127.255.255.255/32 Direct  0   0           127.0.0.1       InLoop0
192.168.1.0/24     BGP     255 0           100.1.1.1       GE0/0
192.168.2.0/24     O_ASE2  150 1           100.2.2.3       GE0/1
224.0.0.0/4        Direct  0   0           0.0.0.0         NULL0
224.0.0.0/24       Direct  0   0           0.0.0.0         NULL0
255.255.255.255/32 Direct  0   0           127.0.0.1       InLoop0
[R3]display ip routing-table 
Destinations : 18	Routes : 18
Destination/Mask   Proto   Pre Cost        NextHop         Interface
0.0.0.0/32         Direct  0   0           127.0.0.1       InLoop0
2.2.2.2/32         O_INTRA 10  1           100.2.2.2       GE0/0
3.3.3.3/32         Direct  0   0           127.0.0.1       InLoop0
4.4.4.4/32         O_INTRA 10  1           100.3.3.4       GE0/1
100.2.2.0/24       Direct  0   0           100.2.2.3       GE0/0
100.2.2.3/32       Direct  0   0           127.0.0.1       InLoop0
100.2.2.255/32     Direct  0   0           100.2.2.3       GE0/0
100.3.3.0/24       Direct  0   0           100.3.3.3       GE0/1
100.3.3.3/32       Direct  0   0           127.0.0.1       InLoop0
100.3.3.255/32     Direct  0   0           100.3.3.3       GE0/1
127.0.0.0/8        Direct  0   0           127.0.0.1       InLoop0
127.0.0.1/32       Direct  0   0           127.0.0.1       InLoop0
127.255.255.255/32 Direct  0   0           127.0.0.1       InLoop0
192.168.1.0/24     O_ASE2  150 1           100.2.2.2       GE0/0
192.168.2.0/24     O_ASE2  150 1           100.3.3.4       GE0/1
224.0.0.0/4        Direct  0   0           0.0.0.0         NULL0
224.0.0.0/24       Direct  0   0           0.0.0.0         NULL0
255.255.255.255/32 Direct  0   0           127.0.0.1       InLoop0
[R4]display ip routing-table 
Destinations : 19	Routes : 19
Destination/Mask   Proto   Pre Cost        NextHop         Interface
0.0.0.0/32         Direct  0   0           127.0.0.1       InLoop0
2.2.2.2/32         O_INTRA 10  2           100.3.3.3       GE0/0
3.3.3.3/32         O_INTRA 10  1           100.3.3.3       GE0/0
4.4.4.4/32         Direct  0   0           127.0.0.1       InLoop0
100.2.2.0/24       O_INTRA 10  2           100.3.3.3       GE0/0
100.3.3.0/24       Direct  0   0           100.3.3.4       GE0/0
100.3.3.4/32       Direct  0   0           127.0.0.1       InLoop0
100.3.3.255/32     Direct  0   0           100.3.3.4       GE0/0
100.4.4.0/24       Direct  0   0           100.4.4.4       GE0/1
100.4.4.4/32       Direct  0   0           127.0.0.1       InLoop0
100.4.4.255/32     Direct  0   0           100.4.4.4       GE0/1
127.0.0.0/8        Direct  0   0           127.0.0.1       InLoop0
127.0.0.1/32       Direct  0   0           127.0.0.1       InLoop0
127.255.255.255/32 Direct  0   0           127.0.0.1       InLoop0
192.168.1.0/24     O_ASE2  150 1           100.3.3.3       GE0/0
192.168.2.0/24     BGP     255 0           100.4.4.5       GE0/1
224.0.0.0/4        Direct  0   0           0.0.0.0         NULL0
224.0.0.0/24       Direct  0   0           0.0.0.0         NULL0
255.255.255.255/32 Direct  0   0           127.0.0.1       InLo
以上可以看到,通过把 BGP 引入到 OSPF,使 R3 可以通过 OSPF 学习到业务网段的路由,以此解决了 BGP 路由黑洞的问题
IBGP邻居设置下一跳为本机前后BGP路由表情况
设置前
删除配置
[R2-bgp-default-ipv4]undo peer 4.4.4.4 next-hop-local
[R4-bgp-default-ipv4]undo peer 2.2.2.2 next-hop-local 
查询BGP路由表
[R1]display bgp routing-table ipv4
 Total number of routes: 1
 BGP local router ID is 192.168.1.1 
 Status codes: * - valid, > - best, d - dampened, h - history,
               s - suppressed, S - stale, i - internal, e - external
               Origin: i - IGP, e - EGP, ? - incomplete
     Network            NextHop         MED        LocPrf     PrefVal Path/Ogn
* >  192.168.1.0        192.168.1.1     0                     32768   i
[R2]display bgp routing-table ipv4
 Total number of routes: 2
 BGP local router ID is 2.2.2.2 
 Status codes: * - valid, > - best, d - dampened, h - history,
               s - suppressed, S - stale, i - internal, e - external
               Origin: i - IGP, e - EGP, ? - incomplete
     Network            NextHop         MED        LocPrf     PrefVal Path/Ogn
* >e 192.168.1.0        100.1.1.1       0                     0       100i
   i 192.168.2.0        100.4.4.5       0          100        0       300i
[R4]display bgp routing-table ipv4
 Total number of routes: 2
 BGP local router ID is 4.4.4.4 
 Status codes: * - valid, > - best, d - dampened, h - history,
               s - suppressed, S - stale, i - internal, e - external
               Origin: i - IGP, e - EGP, ? - incomplete
     Network            NextHop         MED        LocPrf     PrefVal Path/Ogn
   i 192.168.1.0        100.1.1.1       0          100        0       100i
* >e 192.168.2.0        100.4.4.5       0                     0       300i
[R5]display bgp routing-table ipv4
 Total number of routes: 1
 BGP local router ID is 192.168.2.1 
 Status codes: * - valid, > - best, d - dampened, h - history,
               s - suppressed, S - stale, i - internal, e - external
               Origin: i - IGP, e - EGP, ? - incomplete
     Network            NextHop         MED        LocPrf     PrefVal Path/Ogn
* >  192.168.2.0        192.168.2.1     0                     32768   i
以上可以看到,R2把从EBGP邻居得到的路由信息发给它的IBGP邻居时,并不改变该路由信息的下一跳属性,且由于 R2 和 R4 既有 EBGP 邻居,又有 IBGP 邻居,所以为了使从 EBGP 邻居学习的路由传递至 IBGP 邻居时下一跳可达,需要修改 IBGP 邻居下一跳为本机
设置后
[R1]display bgp routing-table ipv4
 Total number of routes: 2
 BGP local router ID is 192.168.1.1 
 Status codes: * - valid, > - best, d - dampened, h - history,
               s - suppressed, S - stale, i - internal, e - external
               Origin: i - IGP, e - EGP, ? - incomplete
     Network            NextHop         MED        LocPrf     PrefVal Path/Ogn
* >  192.168.1.0        192.168.1.1     0                     32768   i
* >e 192.168.2.0        100.1.1.2                             0       200 300i
[R2]display bgp routing-table ipv4
 Total number of routes: 2
 BGP local router ID is 2.2.2.2 
 Status codes: * - valid, > - best, d - dampened, h - history,
               s - suppressed, S - stale, i - internal, e - external
               Origin: i - IGP, e - EGP, ? - incomplete
     Network            NextHop         MED        LocPrf     PrefVal Path/Ogn
* >e 192.168.1.0        100.1.1.1       0                     0       100i
* >i 192.168.2.0        4.4.4.4         0          100        0       300i
[R4]display bgp routing-table ipv4
 Total number of routes: 2
 BGP local router ID is 4.4.4.4 
 Status codes: * - valid, > - best, d - dampened, h - history,
               s - suppressed, S - stale, i - internal, e - external
               Origin: i - IGP, e - EGP, ? - incomplete
     Network            NextHop         MED        LocPrf     PrefVal Path/Ogn
* >i 192.168.1.0        2.2.2.2         0          100        0       100i
* >e 192.168.2.0        100.4.4.5       0                     0       300i
[R5]display bgp routing-table ipv4
 Total number of routes: 2
 BGP local router ID is 192.168.2.1 
 Status codes: * - valid, > - best, d - dampened, h - history,
               s - suppressed, S - stale, i - internal, e - external
               Origin: i - IGP, e - EGP, ? - incomplete
     Network            NextHop         MED        LocPrf     PrefVal Path/Ogn
* >e 192.168.1.0        100.4.4.4                             0       200 100i
* >  192.168.2.0        192.168.2.1     0                     32768   i
实验附件
H3C BGP基本配置实验.7z

![LeetCode 刷题 [C++] 第300题.最长递增子序列](https://img-blog.csdnimg.cn/direct/1a55c8e7afa142b5a4dd669572a42cdc.png)

















