• 产品与解决方案
  • 行业解决方案
  • 服务
  • 支持
  • 合作伙伴
  • 新华三人才研学中心
  • 关于我们

05-三层技术-IP路由配置举例

目录

02-H3C_BGP路由属性控制路由选择典型配置举例

本章节下载 02-H3C_BGP路由属性控制路由选择典型配置举例  (243.29 KB)

02-H3C_BGP路由属性控制路由选择典型配置举例

H3C BGP路由属性控制路由选择典型配置举例

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

资料版本:6W100-20200330

产品版本:Release 7585P05

 

Copyright © 2020 新华三技术有限公司 版权所有,保留一切权利。

非经本公司书面许可,任何单位和个人不得擅自摘抄、复制本文档内容的部分或全部,并不得以任何形式传播。

除新华三技术有限公司的商标外,本手册中出现的其它公司的商标、产品标识及商品名称,由各自权利人拥有。

本文档中的信息可能变动,恕不另行通知。



1  简介

本文档介绍通过使用BGP路由属性控制路由选择的配置举例。

2  配置前提

本文档中的配置均是在实验室环境下进行的配置和验证,配置前设备的所有参数均采用出厂时的缺省配置。如果您已经对设备进行了配置,为了保证配置效果,请确认现有配置和以下举例中的配置不冲突。

本文档假设您已了解BGP特性和路由策略特性。

3  通过AS-Path属性控制路由选择典型配置举例

3.1  组网需求

图1所示,所有设备均运行BGP协议。AS 100和AS 400之间有两条路径可以通信,这两条路径分别经过AS 200和AS 300。现要求通过配置路由策略,实现:

·            AS 100内的设备访问AS 200始发的路由时,优先选择从Device D转发;

·            AS 100内的设备访问AS 300始发的路由时,优先选择从Device E转发;

·            AS 100内的设备访问AS 400始发的路由时,优先选择从Device D转发。

图1 AS-Path属性控制路由选择配置组网图

 

3.2  配置思路

·            为了使AS 100内的设备能够根据路由的始发AS号来选择优先转发路径,需要在AS 100的边缘设备上为特定AS始发的路由提高优先级,并将该路由扩散至AS 100内部:

¡  在Device B上配置路由策略,将从AS 200或AS 400始发的路由的本地优先级设置为300;

¡  在Device C上配置路由策略,将从AS 300始发的路由的本地优先级设置为200。

·            使用AS路径过滤列表来匹配由指定AS始发的路由。

3.3  配置步骤

3.3.1  配置各接口的IP地址

# 配置接口Vlan-interface 12的IP地址。

<DeviceA> system-view

[DeviceA] interface Vlan-interface 12

[DeviceA-Vlan-interface12] ip address 12.12.12.1 24

[DeviceA-Vlan-interface12] quit

# 请参考以上方法配置其它相关接口的IP地址,配置步骤这里省略。

3.3.2  配置BGP连接

# 在Device A上创建本地AS号为100的BGP实例,指定对等体12.12.12.2和13.13.13.3。

[DeviceA] bgp 100

[DeviceA-bgp-default] router-id 1.1.1.1

[DeviceA-bgp-default] peer 12.12.12.2 as-number 100

[DeviceA-bgp-default] peer 13.13.13.3 as-number 100

[DeviceA-bgp-default] address-family ipv4 unicast

[DeviceA-bgp-default-ipv4] peer 12.12.12.2 enable

[DeviceA-bgp-default-ipv4] peer 13.13.13.3 enable

[DeviceA-bgp-default-ipv4] quit

[DeviceA-bgp-default] quit

# 在Device B上创建本地AS号为100的BGP实例,,指定对等体12.12.12.1和24.24.24.4,并引入直连路由。

[DeviceB] bgp 100

[DeviceB-bgp-default] router-id 2.2.2.2

[DeviceB-bgp-default] peer 12.12.12.1 as-number 100

[DeviceB-bgp-default] peer 24.24.24.4 as-number 200

[DeviceB-bgp-default] address-family ipv4 unicast

[DeviceB-bgp-default-ipv4] peer 12.12.12.1 enable

[DeviceB-bgp-default-ipv4] peer 24.24.24.4 enable

[DeviceB-bgp-default-ipv4] import-route direct

[DeviceB-bgp-default-ipv4] quit

[DeviceB-bgp-default] quit

# 在Device C上创建本地AS号为100的BGP实例,指定对等体13.13.13.1和35.35.35.5,并引入直连路由。

[DeviceC] bgp 100

[DeviceC-bgp-default] router-id 3.3.3.3

[DeviceC-bgp-default] peer 13.13.13.1 as-number 100

[DeviceC-bgp-default] peer 35.35.35.5 as-number 300

[DeviceC-bgp-default] address-family ipv4 unicast

[DeviceC-bgp-default-ipv4] peer 13.13.13.1 enable

[DeviceC-bgp-default-ipv4] peer 35.35.35.5 enable

[DeviceC-bgp-default-ipv4] import-route direct

[DeviceC-bgp-default-ipv4] quit

[DeviceC-bgp-default] quit

# 在Device D上创建本地AS号为200的BGP实例,指定对等体24.24.24.2和46.46.46.6,并发布路由4.4.4.4/32。

[DeviceD] bgp 200

[DeviceD-bgp-default] router-id 4.4.4.4

[DeviceD-bgp-default] peer 24.24.24.2 as-number 100

[DeviceD-bgp-default] peer 46.46.46.6 as-number 400

[DeviceD-bgp-default] address-family ipv4 unicast

[DeviceD-bgp-default-ipv4] peer 24.24.24.2 enable

[DeviceD-bgp-default-ipv4] peer 46.46.46.6 enable

[DeviceD-bgp-default-ipv4] network 4.4.4.4 32

[DeviceD-bgp-default-ipv4] quit

[DeviceD-bgp-default] quit

# 在Device E上创建本地AS号为300的BGP实例,指定对等体35.35.35.3和56.56.56.6,并发布路由5.5.5.5/32。

[DeviceE] bgp 300

[DeviceE-bgp-default] router-id 5.5.5.5

[DeviceE-bgp-default] peer 35.35.35.3 as-number 100

[DeviceE-bgp-default] peer 56.56.56.6 as-number 400

[DeviceE-bgp-default] address-family ipv4 unicast

[DeviceE-bgp-default-ipv4] peer 35.35.35.3 enable

[DeviceE-bgp-default-ipv4] peer 56.56.56.6 enable

[DeviceE-bgp-default-ipv4] network 5.5.5.5 32

[DeviceE-bgp-default-ipv4] quit

[DeviceE-bgp-default] quit

# 在Device F上创建本地AS号为400的BGP实例,指定对等体46.46.46.4和56.56.56.5,并发布路由6.6.6.6/32。

[DeviceF] bgp 400

[DeviceF-bgp-default] router-id 6.6.6.6

[DeviceF-bgp-default] peer 46.46.46.4 as-number 200

[DeviceF-bgp-default] peer 56.56.56.5 as-number 300

[DeviceF-bgp-default] address-family ipv4 unicast

[DeviceF-bgp-default-ipv4] peer 46.46.46.4  enable

[DeviceF-bgp-default-ipv4] peer 56.56.56.5 enable

[DeviceF-bgp-default-ipv4] network 6.6.6.6 32

[DeviceF-bgp-default-ipv4] quit

[DeviceF-bgp-default] quit

# 完成以上配置后,在Device A上查看BGP路由表,可以看到Device D、Device E和Device F发布的路由及其AS-Path属性。

[DeviceA] display bgp routing-table ipv4

 

Total number of routes: 12

 

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

 

* >i 2.2.2.2/32         12.12.12.2      0          100        0       ?

* >i 3.3.3.3/32         13.13.13.3      0          100        0       ?

* >i 4.4.4.4/32         24.24.24.4      0          100        0       200i

*  i                    35.35.35.5                 100        0       300 400

                                                                      200i

* >i 5.5.5.5/32         35.35.35.5      0          100        0       300i

*  i                    24.24.24.4                 100        0       200 400

                                                                      300i

* >i 6.6.6.6/32         24.24.24.4                 100        0       200 400i

*  i                    35.35.35.5                 100        0       300 400i

* >i 12.12.12.0/24      12.12.12.2      0          100        0       ?

* >i 13.13.13.0/24      13.13.13.3      0          100        0       ?

* >i 24.24.24.0/24      12.12.12.2      0          100        0       ?

* >i 35.35.35.0/24      13.13.13.3      0          100        0       ?

3.3.3  配置路由策略

# 在Device B上创建路由策略aspath,将AS-Path以200或400结尾的路由的本地优先级设置为300。

[DeviceB] ip as-path 1 permit 200$

[DeviceB] ip as-path 1 permit 400$

[DeviceB] route-policy aspath permit node 10

[DeviceB-route-policy-aspath-10] if-match as-path 1

[DeviceB-route-policy-aspath-10] apply local-preference 300

[DeviceB-route-policy-aspath-10] quit

# 在Device B上配置对从对等体24.24.24.4接收的路由应用路由策略aspath。

[DeviceB] bgp 100

[DeviceB-bgp-default] address-family ipv4

[DeviceB-bgp-default-ipv4] peer 24.24.24.4 route-policy aspath import

# 在Device C上创建路由策略aspath,将AS-Path以300结尾的路由的本地优先级设置为200。

[DeviceC] ip as-path 1 permit 300$

[DeviceC] route-policy aspath permit node 20

[DeviceC-route-policy-aspath-20] if-match as-path 1

[DeviceC-route-policy-aspath-20] apply local-preference 200

[DeviceC-route-policy-aspath-20] quit

# 在Device C上配置对从对等体35.35.35.5接收的路由应用路由策略aspath。

[DeviceC] bgp 100

[DeviceC-bgp-default] address-family ipv4

[DeviceC-bgp-default-ipv4] peer 35.35.35.5 route-policy aspath import

3.4  验证配置

# 在Device A上再次查看BGP路由表,可以看到路由的本地优先级发生了变化,从AS 200和AS 400始发的路由的本地优先级变为300,从AS 300始发的路由的本地优先级变为200。

[DeviceA] display bgp routing-table ipv4

 

Total number of routes: 11

 

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

 

* >i 2.2.2.2/32         12.12.12.2      0          100        0       ?

* >i 3.3.3.3/32         13.13.13.3      0          100        0       ?

* >i 4.4.4.4/32         24.24.24.4      0          300        0       200i

* >i 5.5.5.5/32         35.35.35.5      0          200        0       300i

* >i 6.6.6.6/32         24.24.24.4                 300        0       200 400i

* >i 12.12.12.0/24      12.12.12.2      0          100        0       ?

* >i 13.13.13.0/24      13.13.13.3      0          100        0       ?

* >i 24.24.24.0/24      12.12.12.2      0          100        0       ?

* >i 35.35.35.0/24      13.13.13.3      0          100        0       ?

# 从Device A查看到达6.6.6.6的报文所经过的路径,可以看出报文通过Device D转发。

[DeviceA] tracert 6.6.6.6

traceroute to 6.6.6.6 (6.6.6.6), 30 hops at most, 52 bytes each packet, press CT

RL_C to break

 1  12.12.12.2 (12.12.12.2)  2.417 ms  1.887 ms  1.773 ms

 2  24.24.24.4 (24.24.24.4)  4.057 ms  2.293 ms  2.739 ms

 3  6.6.6.6 (6.6.6.6)  5.145 ms  4.205 ms  4.402 ms

3.5  配置文件

·            Device A:

#

vlan 12

#

vlan 13

#

interface LoopBack0

 ip address 1.1.1.1 255.255.255.255

#

interface Vlan-interface12

 ip address 12.12.12.1 255.255.255.0

#

interface Vlan-interface13

 ip address 13.13.13.1 255.255.255.0

#

bgp 100

 router-id 1.1.1.1

 peer 12.12.12.2 as-number 100

 peer 13.13.13.3 as-number 100

 #

 address-family ipv4 unicast

  peer 12.12.12.2 enable

  peer 13.13.13.3 enable

#

·            Device B :

#

vlan 12

#

vlan 24

#

interface LoopBack0

 ip address 2.2.2.2 255.255.255.255

#

interface Vlan-interface12

 ip address 12.12.12.2 255.255.255.0

#

interface Vlan-interface24

 ip address 24。24.24.2 255.255.255.0

#

bgp 100

 router-id 2.2.2.2

 peer 12.12.12.1 as-number 100

 peer 24.24.24.4 as-number 200

 #

 address-family ipv4 unicast

  import-route direct

  peer 12.12.12.1 enable

  peer 24.24.24.4 enable

  peer 24.24.24.4 route-policy aspath import

#

route-policy aspath permit node 10

 if-match as-path 1

 apply local-preference 300

#

 ip as-path 1 permit 200$

 ip as-path 1 permit 400$

#

·            Device C:

#

vlan 13

#

vlan 35

#

interface LoopBack0

 ip address 3.3.3.3 255.255.255.255

#

interface Vlan-interface13

 ip address 13.13.13.3 255.255.255.0

#

interface Vlan-interface35

 ip address 35.35.35.3 255.255.255.0

#

bgp 100

 router-id 3.3.3.3

 peer 13.13.13.1 as-number 100

 peer 35.35.35.5 as-number 300

 #

 address-family ipv4 unicast

  import-route direct

  peer 13.13.13.1 enable

  peer 35.35.35.5 enable

  peer 35.35.35.5 route-policy aspath import

#

route-policy aspath permit node 20

 if-match as-path 1

 apply local-preference 200

#

 ip as-path 1 permit 300$

#

·            Device D :

#

vlan 24

#

vlan 46

#

interface LoopBack0

 ip address 4.4.4.4 255.255.255.255

#

interface Vlan-interface24

 ip address 24.24.24.4 255.255.255.0

#

interface Vlan-interface46

 ip address 46.46.46.4 255.255.255.0

#

bgp 200

 router-id 4.4.4.4

 peer 24.24.24.2 as-number 100

 peer 46.46.46.6 as-number 400

 #

 address-family ipv4 unicast

  network 4.4.4.4 255.255.255.255

  peer 24.24.24.2 enable

  peer 46.46.46.6 enable

#

·            Device E :

#

vlan 35

#

vlan 56

#

interface LoopBack0

 ip address 5.5.5.5 255.255.255.255

#

interface Vlan-interface35

 ip address 35.35.35.5 255.255.255.0

#

interface Vlan-interface56

 ip address 56.56.56.5 255.255.255.0

#

bgp 300

 router-id 5.5.5.5

 peer 35.35.35.3 as-number 100

 peer 56.56.56.6 as-number 400

 #

 address-family ipv4 unicast

  network 5.5.5.5 255.255.255.255

  peer 35.35.35.3 enable

  peer 56.56.56.6 enable

#

·            Device F :

#

vlan 46

#

vlan 56

#

interface LoopBack0

 ip address 6.6.6.6 255.255.255.255

#

interface Vlan-interface46

 ip address 46.46.46.6 255.255.255.0

#

interface Vlan-interface56

 ip address 56.56.56.6 255.255.255.0

#

bgp 400

 router-id 6.6.6.6

 peer 46.46.46.4 as-number 200

 peer 56.56.56.5 as-number 300

 #

 address-family ipv4 unicast

  network 6.6.6.6 255.255.255.255

  peer 46.46.46.4 enable

  peer 56.56.56.5 enable

#

4  通过MED属性控制路由选择典型配置举例

4.1  组网需求

图2所示,所有设备均运行BGP协议。Device A与Device B、Device C之间运行EBGP,Device B、Device C之间运行IBGP。由于Device B的Router ID小于Device C的Router ID,所以当AS 100访问AS 200时,流量优先选择从Device B转发。现要求通过配置路由策略,实现AS 100访问AS 200的流量优先选择通过Device C转发。

图2 MED属性控制路由选择配置组网图

 

4.2  配置思路

为了实现AS 100访问AS 200的流量优先选择通过Device C转发,需要通过路由策略修改Device B发送给Device A的MED值,使其大于缺省MED值0。

4.3  配置步骤

4.3.1  基础配置

# 配置接口Vlan-interface 12的IP地址。

<DeviceA> system-view

[DeviceA] interface Vlan-interface 12

[DeviceA-Vlan-interface12] ip address 12.12.12.1 24

[DeviceA-Vlan-interface12] quit

# 请参考以上方法配置其它相关接口的IP地址,配置步骤这里省略。

# 在Device A上创建本地AS号为100的BGP实例,指定对等体12.12.12.2和13.13.13.3。

[DeviceA] bgp 100

[DeviceA-bgp-default] router-id 1.1.1.1

[DeviceA-bgp-default] peer 12.12.12.2 as-number 200

[DeviceA-bgp-default] peer 13.13.13.3 as-number 200

[DeviceA-bgp-default] address-family ipv4 unicast

[DeviceA-bgp-default-ipv4] peer 12.12.12.2 enable

[DeviceA-bgp-default-ipv4] peer 13.13.13.3 enable

[DeviceA-bgp-default-ipv4] quit

[DeviceA-bgp-default] quit

# 在Device B上创建本地AS号为200的BGP实例,指定对等体12.12.12.1和3.3.3.3。

[DeviceB] bgp 200

[DeviceB-bgp-default] router-id 2.2.2.2

[DeviceB-bgp-default] peer 12.12.12.1 as-number 100

[DeviceB-bgp-default] peer 3.3.3.3 as-number 200

[DeviceB-bgp-default] peer 3.3.3.3 connect-interface LoopBack0

[DeviceB-bgp-default] address-family ipv4 unicast

[DeviceB-bgp-default-ipv4] peer 12.12.12.1 enable

[DeviceB-bgp-default-ipv4] peer 3.3.3.3 enable

[DeviceB-bgp-default-ipv4] network 23.23.23.0 24

[DeviceB-bgp-default-ipv4] quit

[DeviceB-bgp-default] quit

# 在Device B上配置目的地址为3.3.3.3/32的静态路由,以保证对等体3.3.3.3可达。

[DeviceB] ip route-static 3.3.3.3 32 23.23.23.3

# 在Device C上创建本地AS号为200的BGP实例,指定对等体13.13.13.1和2.2.2.2。

[DeviceC] bgp 200

[DeviceC-bgp-default] router-id 3.3.3.3

[DeviceC-bgp-default] peer 13.13.13.1 as-number 100

[DeviceC-bgp-default] peer 2.2.2.2 as-number 200

[DeviceC-bgp-default] peer 2.2.2.2 connect-interface LoopBack0

[DeviceC-bgp-default] address-family ipv4 unicast

[DeviceC-bgp-default-ipv4] peer 13.13.13.1 enable

[DeviceC-bgp-default-ipv4] peer 2.2.2.2 enable

[DeviceC-bgp-default-ipv4] network 23.23.23.0 24

[DeviceC-bgp-default-ipv4] quit

[DeviceC-bgp-default] quit

# 在Device C上配置目的地址为2.2.2.2/32的静态路由,以保证对等体2.2.2.2可达。

[DeviceC] ip route-static 2.2.2.2 32 23.23.23.2

# 完成以上配置后,在Device A上查看BGP路由表,可以看到前往23.23.23.0/24网段的两条有效路由,其中下一跳为12.12.12.2的路由为最优路由,这是由于Device B的Router ID较小。

[DeviceA] display bgp routing-table ipv4

 

 Total number of routes: 2

 

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

 

* >e 23.23.23.0/24      12.12.12.2      0                     0       200i

*  e                    13.13.13.3      0                     0       200i

4.3.2  配置路由策略

# 在Device B上创建路由策略10,将路由开销修改为100。

[DeviceB] route-policy 10 permit node 10

[DeviceB-route-policy-10-10] apply cost 100

[DeviceB-route-policy-10-10] quit

# 在Device B上配置对向对等体12.12.12.1发送的路由应用路由策略10,即修改Device B发送给Device A的MED值为100。

[DeviceB] bgp 200

[DeviceB-bgp-default] address-family ipv4 unicast

[DeviceB-bgp-default-ipv4] peer 12.12.12.1 route-policy 10 export

[DeviceB-bgp-default-ipv4] quit

[DeviceB-bgp-default] quit

4.4  验证配置

# 查看Device A的BGP路由表,可以看到下一跳为12.12.12.2的路由的MED值变为100,下一跳为13.13.13.3的路由成为了最优路由。

[DeviceA] display bgp routing-table ipv4

 

 Total number of routes: 2

 

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

 

* >e 23.23.23.0/24      13.13.13.3      0                     0       200i

*  e                    12.12.12.2      100                   0       200i

4.5  配置文件

·            Device A:

#

vlan 12

#

vlan 13

#

interface LoopBack0

 ip address 1.1.1.1 255.255.255.255

#

interface Vlan-interface12

 ip address 12.12.12.1 255.255.255.0

#

interface Vlan-interface13

 ip address 13.13.13.1 255.255.255.0

#

bgp 100

 router-id 1.1.1.1

 peer 12.12.12.2 as-number 200

 peer 13.13.13.3 as-number 200

 #

 address-family ipv4 unicast

  peer 12.12.12.2 enable

  peer 13.13.13.3 enable

#

·            Device B:

#

vlan 12

#

vlan 23

#

interface LoopBack0

 ip address 2.2.2.2 255.255.255.255

#

interface Vlan-interface12

 ip address 12.12.12.2 255.255.255.0

#

interface Vlan-interface23

 ip address 23.23.23.2 255.255.255.0

#

bgp 200

 router-id 2.2.2.2

 peer 3.3.3.3 as-number 200

 peer 3.3.3.3 connect-interface LoopBack0

 peer 12.12.12.1 as-number 100

 #

 address-family ipv4 unicast

  network 23.23.23.0 255.255.255.0

  peer 3.3.3.3 enable

  peer 12.12.12.1 enable

  peer 12.12.12.1 route-policy 10 export

#

route-policy 10 permit node 10

 apply cost 100

#

 ip route-static 3.3.3.3 32 23.23.23.3

#

·            Device C:

#

vlan 13

#

vlan 23

#

interface LoopBack0

 ip address 3.3.3.3 255.255.255.255

#

interface Vlan-interface13

 ip address 13.13.13.3 255.255.255.0

#

interface Vlan-interface23

 ip address 23.23.23.3 255.255.255.0

#

bgp 200

 router-id 3.3.3.3

 peer 2.2.2.2 as-number 200

 peer 2.2.2.2 connect-interface LoopBack0

 peer 13.13.13.1 as-number 100

 #

 address-family ipv4 unicast

  network 23.23.23.0 255.255.255.0

  peer 2.2.2.2 enable

  peer 13.13.13.1 enable

#

 ip route-static 2.2.2.2 32 23.23.23.2

#

5  相关资料

·            H3C S10500系列交换机 三层技术-IP路由配置指导-R758X

·            H3C S10500系列交换机 三层技术-IP路由命令参考-R758X

 

不同款型规格的资料略有差异, 详细信息请向具体销售和400咨询。H3C保留在没有任何通知或提示的情况下对资料内容进行修改的权利!

新华三官网
联系我们