H3C BGP 路由控制实验

本文详细描述了在H3C网络环境中进行的一次BGP路由控制实验,通过修改MED、Preferred-value、AS_path和Local-pref属性,实现了不同路由经过特定设备的目的。实验中配置了OSPF、EBGP和IBGP邻居关系,并展示了如何通过BGP路由策略优化路由选择。

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

H3C BGP 路由控制实验

实验拓扑

image

实验需求

  1. 按照需求配置 IP 地址,R1 和 R4 配置环回口模拟业务网段,R2 和 R3 配置 Loopback0 口地址作为 OSPF 的 Router-id 和 IBGP 邻居地址
  2. AS 200 内部配置 OSPF,仅用于实现 BGP 的 TCP 可达,不允许宣告业务网段
  3. 配置 BGP,R1 和 R2/R3 建立 EBGP 邻居,R4 和 R2/R3 建立 IBGP 邻居,R1 和 R4 分别把业务网段宣告进 BGP
  4. 通过修改 MED 使 R1 到达192.168.2.0/24​网段的路由经过 R3
  5. 通过修改 Preferred-value 属性,使 R4 到达192.168.0.0/24​网段的路由经过 R3
  6. 通过修改 AS_path 属性,使 R1 到达192.168.3.0/24​网段的路由经过 R3
  7. 通过修改 Local-pref 属性,使 R4 到达192.168.1.0/24​网段的路由经过 R3

实验步骤

OSPF和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       --           --
GE0/1               up       up       100.3.3.1/24       --           --
Loop0               up       up(s)    192.168.0.1/24     --           --
Loop1               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.3.3.3/24       --           --
GE0/1               up       up       100.4.4.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.2.2.4/24       --           --
GE0/1               up       up       100.4.4.4/24       --           --
Loop0               up       up(s)    4.4.4.4/32         --           --
Loop1               up       up(s)    192.168.2.1/24     --           --
Loop2               up       up(s)    192.168.3.1/24     --           --
AS200内部配置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.4.4.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.2.2.4 0.0.0.0
  network 100.4.4.4 0.0.0.0
R1 和 R2/R3 建立 EBGP 邻居,业务网段宣告
R1 BGP配置
bgp 100
 peer 100.1.1.2 as-number 200
 peer 100.3.3.3 as-number 200
 #
 address-family ipv4 unicast
  network 192.168.0.0 255.255.255.0
  network 192.168.1.0 255.255.255.0
  peer 100.1.1.2 enable
  peer 100.3.3.3 enable
R2 BGP配置
bgp 200
 peer 100.1.1.1 as-number 100
 #
 address-family ipv4 unicast
  peer 100.1.1.1 enable
R3 BGP配置
bgp 200
 peer 100.3.3.1 as-number 100
 #
 address-family ipv4 unicast
  peer 100.3.3.1 enable
R4 和 R2/R3 建立 IBGP 邻居,业务网段宣告
R4 BGP配置
bgp 200
 peer 2.2.2.2 as-number 200
 peer 2.2.2.2 connect-interface LoopBack0
 peer 3.3.3.3 as-number 200
 peer 3.3.3.3 connect-interface LoopBack0
 #
 address-family ipv4 unicast
  network 192.168.2.0 255.255.255.0
  network 192.168.3.0 255.255.255.0
  peer 2.2.2.2 enable
  peer 3.3.3.3 enable
R2 BGP配置
bgp 200
 peer 4.4.4.4 as-number 200
 peer 4.4.4.4 connect-interface LoopBack0
 #
 address-family ipv4 unicast
  peer 4.4.4.4 enable
  peer 4.4.4.4 next-hop-local
R3 BGP配置
bgp 200
 peer 4.4.4.4 as-number 200
 peer 4.4.4.4 connect-interface LoopBack0
 #
 address-family ipv4 unicast
  peer 4.4.4.4 enable
  peer 4.4.4.4 next-hop-local

BGP路由控制配置

分析:依据BGP13条选路原则,在其它属性都是一致的情况下,路由器优选IP地址最小的对等体发布的路由,所以目前的业务网段路由应都是优选R2

[R1]display bgp routing-table ipv4

 Total number of routes: 6

 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.0.0        192.168.0.1     0                     32768   i
* >  192.168.1.0        192.168.1.1     0                     32768   i
* >e 192.168.2.0        100.3.3.3                             0       200i
*  e                    100.1.1.2                             0       200i
* >e 192.168.3.0        100.3.3.3                             0       200i
*  e                    100.1.1.2                             0       200i

[R4]display bgp routing-table ipv4

 Total number of routes: 6

 BGP local router ID is 192.168.3.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

* >i 192.168.0.0        2.2.2.2         0          100        0       100i
*  i                    3.3.3.3         0          100        0       100i
* >i 192.168.1.0        2.2.2.2         0          100        0       100i
*  i                    3.3.3.3         0          100        0       100i
* >  192.168.2.0        192.168.2.1     0                     32768   i
* >  192.168.3.0        192.168.3.1     0                     32768   i
通过修改MED属性

实验需求:通过修改 MED 使 R1 到达192.168.2.0/24​网段的路由经过 R3

MED 类似 IGP 中的 Cost,越小越优先,由 network 命令产生的 BGP 路由默认 MED 为 0。把 R2 传递至 R1 的该网段路由 MED 改大即可实现效果
在R2上配置ACL抓取业务网段192.168.2.0/24​​
acl basic 2000
 description Grab 192.168.2.0/24
 rule 0 permit source 192.168.2.0 0.0.0.255
配置route-policy引用上述ACL策略,修改Cost值为100
#          
route-policy Control-MED permit node 10
 if-match ip address acl 2000
 apply cost 100
#
route-policy Control-MED permit node 100    //空节点放行所有
在 R2 上对 R1 调用route-policy,应用方向为出方向
bgp 200
 address-family ipv4 unicast
  peer 100.1.1.1 route-policy Control-MED export
效果测试

在 R1 上查看 BGP 路由表,发现到达192.168.2.0/24​网段的路由已经变为选择 R3

[R1]dis bgp rou ipv4

 Total number of routes: 6

 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.0.0        192.168.0.1     0                     32768   i
* >  192.168.1.0        192.168.1.1     0                     32768   i
* >e 192.168.2.0        100.3.3.3                             0       200i
*  e                    100.1.1.2       100                   0       200i
* >e 192.168.3.0        100.1.1.2                             0       200i
*  e                    100.3.3.3                             0       200i
通过修改 Preferred-value 属性

实验需求:通过修改 Preferred-value 属性,使 R4 到达 192.168.0.0/24​ 网段的路由经过 R3

Preferred-value 是私有属性,仅在本机有效,越大越优先,通过其它邻居学习到的路由默认 Preferred-value 为 0。把 R4 从 R3 学习的该网段路由 Preferred-value 改大即可实现效果
在R4上配置ACL抓取业务网段192.168.0.0/24
acl basic 2000
 description Grab 192.168.0.0/24
 rule 0 permit source 192.168.0.0 0.0.0.255
配置route-policy引用上述ACL策略,修改Preferred-value值为100
#
route-policy Control-PV permit node 10
 if-match ip address acl 2000
 apply preferred-value 100
#
route-policy Control-PV permit node 100
在 R4 上对 R3 调用route-policy,应用方向为入方向
bgp 200
 address-family ipv4 unicast
  peer 3.3.3.3 route-policy Control-PV import
效果测试

在 R4 上查看 BGP 路由表,发现到达192.168.0.0/24​网段的路由已经变为选择 R3

[R4]display bgp routing-table ipv4

 Total number of routes: 6

 BGP local router ID is 192.168.3.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

* >i 192.168.0.0        3.3.3.3         0          100        100     100i
*  i                    2.2.2.2         0          100        0       100i
* >i 192.168.1.0        2.2.2.2         0          100        0       100i
*  i                    3.3.3.3         0          100        0       100i
* >  192.168.2.0        192.168.2.1     0                     32768   i
* >  192.168.3.0        192.168.3.1     0                     32768   i
通过修改 AS_path 属性

实验需求:通过修改 AS_path 属性,使 R1 到达 192.168.3.0/24​ 网段的路由经过 R3

AS\_path 属性用于描述该路由传递所经过的 AS 路径,越短越优先,R1 收到的该网段路由从 AS 200 始发,然后进入本 AS,所以 AS\_path 属性为200i。把 R1 从 R2 学习的该网段路由 AS\_path 改长即可实现效果
在R1上配置ACL抓取业务网段192.168.3.0/24
acl basic 2000
 description Grab 192.168.3.0/24
 rule 0 permit source 192.168.3.0 0.0.0.255
配置route-policy引用上述ACL策略,修改AS_path值为200 200 200
#
route-policy Control-AS_Path permit node 10
 if-match ip address acl 2000
 apply as-path 200 200 200
#
route-policy Control-AS_Path permit node 100
在 R1 上对 R2 调用route-policy,应用方向为入方向
bgp 100
 #
 address-family ipv4 unicast
  peer 100.1.1.2 route-policy Control-AS_Path import
测试效果

在 R1 上查看 BGP 路由表,发现到达 192.168.3.0/24 网段的路由已经变为选择 R3

[R1]display bgp routing-table ipv4

 Total number of routes: 6

 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.0.0        192.168.0.1     0                     32768   i
* >  192.168.1.0        192.168.1.1     0                     32768   i
* >e 192.168.2.0        100.3.3.3                             0       200i
*  e                    100.1.1.2       100                   0       200i
* >e 192.168.3.0        100.3.3.3                             0       200i
*  e                    100.1.1.2                             0       200 200 200 200i
通过修改 Local-pref 属性

实验需求:通过修改 Local-pref 属性,使 R4 到达 192.168.1.0/24​ 网段的路由经过 R3

Local-pref 越大越优先,默认值为 100。把 R3 向 R4 发布的该网段路由 Local-pref 改大即可实现效果
在R3上配置ACL抓取业务网段192.168.1.0/24
acl basic 2000
 description Grab 192.168.1.0/24
 rule 0 permit source 192.168.1.0 0.0.0.255
配置route-policy引用上述ACL策略,修改Local-pref值为200
#
route-policy Control-LP permit node 10
 if-match ip address acl 2000
 apply local-preference 200
#
route-policy Control-LP permit node 100
在 R3 上对 R4 调用route-policy,应用方向为出方向
bgp 200
 address-family ipv4 unicast
  peer 4.4.4.4 route-policy Control-LP export
效果测试

在 R14上查看 BGP 路由表,发现到达192.168.1.0/24​网段的路由已经变为选择 R3

[R4]display bgp routing-table ipv4

 Total number of routes: 6

 BGP local router ID is 192.168.3.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

* >i 192.168.0.0        3.3.3.3         0          100        100     100i
*  i                    2.2.2.2         0          100        0       100i
* >i 192.168.1.0        3.3.3.3         0          200        0       100i
*  i                    2.2.2.2         0          100        0       100i
* >  192.168.2.0        192.168.2.1     0                     32768   i
* >  192.168.3.0        192.168.3.1     0                     32768   i

实验验证

实验需求:

通过修改 MED 使 R1 到达`192.168.2.0/24`​网段的路由经过 R3

通过修改 Preferred-value 属性,使 R4 到达`192.168.0.0/24`​网段的路由经过 R3

通过修改 AS_path 属性,使 R1 到达`192.168.3.0/24`​网段的路由经过 R3

通过修改 Local-pref 属性,使 R4 到达`192.168.1.0/24`​网段的路由经过 R3

通过查看R1和R4的BGP路由,业务网段互访都是优选R3

[R1]display bgp routing-table ipv4

 Total number of routes: 6

 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.0.0        192.168.0.1     0                     32768   i
* >  192.168.1.0        192.168.1.1     0                     32768   i
* >e 192.168.2.0        100.3.3.3                             0       200i
*  e                    100.1.1.2       100                   0       200i
* >e 192.168.3.0        100.3.3.3                             0       200i
*  e                    100.1.1.2                             0       200 200 200 200i

[R4]display bgp routing-table ipv4

 Total number of routes: 6

 BGP local router ID is 192.168.3.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

* >i 192.168.0.0        3.3.3.3         0          100        100     100i
*  i                    2.2.2.2         0          100        0       100i
* >i 192.168.1.0        3.3.3.3         0          200        0       100i
*  i                    2.2.2.2         0          100        0       100i
* >  192.168.2.0        192.168.2.1     0                     32768   i
* >  192.168.3.0        192.168.3.1     0                     32768   i

实验附件

H3C BGP路由控制实验.zip

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

M建

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值