【微|信|公|众|号:厦门微思网络】

组网需求

如图1所示,某公司的部门A和部门B相距较远,Router_1和Router_6分别作为这两个部门的出口设备,AS 100内部使用OSPF作为IGP。现要求:

通过部署BGP,使部门A和部门B可以通信。

通过配置路由策略,将Router_2 <-> Router_3 <-> Router_4链路作为主链路,负责转发Router_1和Router_6之间的流量;当主链路断开时,自动切换到Router_2 <-> Router_5 <-> Router_4这条路径进行通信。

一文教你如何配置路由策略_路由表

图1 配置路由策略基本功能组网图


操作步骤


1、Router_1的配置

sysname Router_1
#
interface GigabitEthernet1/0/1
 ip address 10.10.0.1 255.255.255.0
#
interface GigabitEthernet2/0/1
 ip address 10.20.0.1 255.255.255.0
#
bgp 200    //启动BGP,指定本地AS号为200,指定BGP路由器的Router ID为1.1.1.1
 router-id 1.1.1.1
 peer 10.20.0.2 as-number 100    //配置Router_1和Router_2建立EBGP连接
#
 ipv4-family unicast
  undo synchronization
  network 10.10.0.0 255.255.255.0    //在BGP IPv4单播地址族视图下,将本地路由表中到达10.10.0.0/24网段的路由添加到BGP路由表中
  peer 10.20.0.2 enable

2、Router_2的配置

sysname Router_2
#
acl number 2000    //创建ACL 2000,允许源IP地址为10.20.0.0/24的报文通过
 rule 0 permit source 10.20.0.0 0.0.0.255
#
interface GigabitEthernet2/0/1
 ip address 10.1.0.101 255.255.255.0
#
interface GigabitEthernet2/0/2
 ip address 10.30.0.101 255.255.255.0
#
interface GigabitEthernet2/0/3
 ip address 10.20.0.2 255.255.255.0
#
bgp 100    //启动BGP,指定本地AS号为100,指定BGP路由器的Router ID为2.2.2.2
 router-id 2.2.2.2
 peer 10.2.0.101 as-number 100    //配置Router_2和Router_4建立IBGP连接
 peer 10.40.1.101 as-number 100
 peer 10.20.0.1 as-number 200    //配置Router_2和Router_1建立EBGP连接
#
 ipv4-family unicast
  undo synchronization
  preference 255 100 130    //配置EBGP路由优先级为255,配置IBGP路由优先级为100,配置本地路由优先级为130,使IBGP路由优先级优于OSPF路由
  peer 10.2.0.101 enable
  peer 10.2.0.101 route-policy local-pre export    //指定向对等体10.2.0.101发布的路由策略为local-pre
  peer 10.2.0.101 next-hop-local    //在BGP IPv4单播地址族视图下,配置向对等体10.2.0.101发布BGP路由时,将下一跳属性修改为自身的地址
  peer 10.20.0.1 enable
  peer 10.40.1.101 enable
  peer 10.40.1.101 next-hop-local    //在BGP IPv4单播地址族视图下,配置向对等体10.40.1.101发布BGP路由时,将下一跳属性修改为自身的地址
#
ospf 1
 import-route direct
 import-route bgp
 area 0.0.0.0
  network 10.1.0.0 0.0.0.255
  network 10.30.0.0 0.0.0.255
#
route-policy local-pre permit node 10    //配置路由策略,将从对等体10.20.0.1学习到的路由发布给对等体10.2.0.101时,设置本地优先级为200
 if-match ip route-source acl 2000
 apply local-preference 200

3、Router_3的配置

sysname Router_3
#
interface GigabitEthernet2/0/1
 ip address 10.1.0.102 255.255.255.0
#
interface GigabitEthernet2/0/2
 ip address 10.2.0.102 255.255.255.0
#
ospf 1
 area 0.0.0.0
  network 10.1.0.0 0.0.0.255
  network 10.2.0.0 0.0.0.255

4、Router_4的配置

sysname Router_4
#
acl number 2000    //创建ACL 2000,允许源IP地址为10.50.0.0/24的报文通过
 rule 0 permit source 10.50.0.0 0.0.0.255
#
interface GigabitEthernet2/0/1
 ip address 10.2.0.101 255.255.255.0
#
interface GigabitEthernet2/0/2
 ip address 10.40.1.101 255.255.255.0
#
interface GigabitEthernet2/0/3
 ip address 10.50.0.2 255.255.255.0
#
bgp 100    //启动BGP,指定本地AS号为100,指定BGP路由器的Router ID为4.4.4.4
 router-id 4.4.4.4
 peer 10.1.0.101 as-number 100    //配置Router_4和Router_2建立IBGP连接
 peer 10.50.0.1 as-number 300    //配置Router_4和Router_6建立EBGP连接
 peer 10.30.0.101 as-number 100    //配置Router_4和Router_2建立IBGP连接
 #
 ipv4-family unicast
  undo synchronization
  preference 255 100 130    //配置EBGP路由优先级为255,配置IBGP路由优先级为100,配置本地路由优先级为130,使IBGP路由优先级优于OSPF路由
  peer 10.1.0.101 enable
  peer 10.1.0.101 next-hop-local    //在BGP IPv4单播地址族视图下,配置向对等体10.1.0.101发布BGP路由时,将下一跳属性修改为自身的地址
  peer 10.1.0.101 route-policy local-pre export
  peer 10.30.0.101 enable
  peer 10.30.0.101 next-hop-local    //在BGP IPv4单播地址族视图下,配置向对等体10.30.0.101发布BGP路由时,将下一跳属性修改为自身的地址
  peer 10.50.0.1 enable
#
ospf 1
 import-route direct
 import-route bgp
 area 0.0.0.0
  network 10.2.0.0 0.0.0.255
  network 10.40.1.0 0.0.0.255
#
route-policy local-pre permit node 10    //配置路由策略,将从对等体10.50.0.1学习到的路由发布给对等体10.1.0.101时,设置本地优先级为200
 if-match ip route-source acl 2000
 apply local-preference 200

5、Router_5的配置

sysname Router_5
#
interface GigabitEthernet2/0/1
 ip address 10.30.0.102 255.255.255.0
#
interface GigabitEthernet2/0/2
 ip address 10.40.1.102 255.255.255.0
#
ospf 1
 area 0.0.0.0
  network 10.40.1.0 0.0.0.255
  network 10.30.0.0 0.0.0.255

6、Router_6的配置

[sysname Router_6
#
interface GigabitEthernet2/0/1
 ip address 10.50.0.1 255.255.255.0
#
interface GigabitEthernet1/0/1
 ip address 10.60.0.1 255.255.255.0
#
bgp 300    //启动BGP,指定本地AS号为300,指定BGP路由器的Router ID为6.6.6.6
 router-id 6.6.6.6
 peer 10.50.0.2 as-number 100    //配置Router_6和Router_4建立EBGP连接
 #
 ipv4-family unicast
  undo synchronization
  network 10.60.0.0 255.255.255.0    //在BGP IPv4单播地址族视图下,将本地路由表中到达10.60.0.0/24网段的路由添加到BGP路由表中
  peer 10.50.0.2 enable

7、验证配置结果

在PC_1上可以执行ping命令到PC_6的IP地址路由可达,证明PC_1和PC_6可以通信。在Router_2上使用display bgp routing-table命令查看BGP路由表,可以看到2条10.60.0.0/24的路由,本地路由优先级分别为100和200。在PC_1上tracert PC_6,查看到报文传输路径是Router_1 <-> Router_2 <-> Router_3 <-> Router_4 <-> Router_6。主链路断开后再查看Router_2的BGP路由表,存在1条10.60.0.0/24的路由。再次在PC_1上tracert PC_6,查看到报文传输路径是Router_1 <-> Router_2 <-> Router_5 <-> Router_4 <-> Router_6,表明主备链路切换成功。