玩转华为ENSP模拟器系列 | 对接收和发布的路由进行过滤示例

素材来源:华为路由器配置指南

一边学习一边整理试验笔记,并与大家分享,侵权即删,谢谢支持!

附上汇总贴:玩转华为ENSP模拟器系列 | 合集_COCOgsta的博客-CSDN博客_ensp实验大全


目标

网络中可根据通信需求,对接收和发布的路由请用过滤器。

组网需求

如图1,运行OSPF协议的网络中,DeviceA从Internet网络接收路由,并为DeviceB提供了部分Internet路由。要求DeviceA仅提供172.1.17.0/24、172.1.18.0/24、172.1.19.0/24给DeviceB,DeviceC仅接收路由172.1.18.0/24,DeviceD接收DeviceB提供的全部路由。

配置思路

  • 在DeviceA、DeviceB、DeviceC和DeviceD上配置OSPF基本功能。
  • 在DeviceA上配置静态路由,并将这些路由引入OSPF路由。
  • 在DeviceA上配置路由发布策略,在DeviceB上查看过滤结果。
  • 在DeviceC上配置路由接收策略,在DeviceC上查看过滤结果。

操作步骤

  1. 配置各接口的IP地址(略)
  2. 配置OSPF协议

DeviceA的配置

DeviceA:
ospf 1
 area 0.0.0.0
  network 192.158.1.0 0.0.0.255

DeviceB的配置

DeviceB:
ospf 1
 area 0.0.0.0
  network 192.158.1.0 0.0.0.255
  network 192.158.2.0 0.0.0.255
  network 192.158.3.0 0.0.0.255

DeviceC的配置

DeviceC:
ospf 1
 area 0.0.0.0
  network 192.158.2.0 0.0.0.255

DeviceD的配置

DeviceD:
ospf 1
 area 0.0.0.0
  network 192.158.3.0 0.0.0.255
  1. 在DeviceA上配置5条静态路由,并将这些静态路由引入到OSPF协议中。
DeviceA:
ip route-static 172.1.16.0 255.255.255.0 NULL0
ip route-static 172.1.17.0 255.255.255.0 NULL0
ip route-static 172.1.18.0 255.255.255.0 NULL0
ip route-static 172.1.19.0 255.255.255.0 NULL0
ip route-static 172.1.20.0 255.255.255.0 NULL0
ospf 1
 import-route static

在DeviceB上查看IP路由表,可以看到OSPF引入的5条静态路由。

[~DeviceB]dis ip routing-table
Route Flags: R - relay, D - download to fib, T - to vpn-instance, B - black hole route
------------------------------------------------------------------------------
Routing Table : _public_
         Destinations : 18       Routes : 18        
Destination/Mask    Proto   Pre  Cost        Flags NextHop         Interface
      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
     172.1.16.0/24  O_ASE   150  1             D   192.158.1.1     Ethernet1/0/1
     172.1.17.0/24  O_ASE   150  1             D   192.158.1.1     Ethernet1/0/1
     172.1.18.0/24  O_ASE   150  1             D   192.158.1.1     Ethernet1/0/1
     172.1.19.0/24  O_ASE   150  1             D   192.158.1.1     Ethernet1/0/1
     172.1.20.0/24  O_ASE   150  1             D   192.158.1.1     Ethernet1/0/1
    192.158.1.0/24  Direct  0    0             D   192.158.1.2     Ethernet1/0/1
    192.158.1.2/32  Direct  0    0             D   127.0.0.1       Ethernet1/0/1
  192.158.1.255/32  Direct  0    0             D   127.0.0.1       Ethernet1/0/1
    192.158.2.0/24  Direct  0    0             D   192.158.2.1     Ethernet1/0/0
    192.158.2.1/32  Direct  0    0             D   127.0.0.1       Ethernet1/0/0
  192.158.2.255/32  Direct  0    0             D   127.0.0.1       Ethernet1/0/0
    192.158.3.0/24  Direct  0    0             D   192.158.3.1     Ethernet1/0/2
    192.158.3.1/32  Direct  0    0             D   127.0.0.1       Ethernet1/0/2
  192.158.3.255/32  Direct  0    0             D   127.0.0.1       Ethernet1/0/2
255.255.255.255/32  Direct  0    0             D   127.0.0.1       InLoopBack0
[~DeviceB]
  1. 配置路由发布策略

在DeviceA上配置地址前缀列表a2b。

DeviceA:
ip ip-prefix a2b index 10 permit 172.1.17.0 24
ip ip-prefix a2b index 20 permit 172.1.18.0 24
ip ip-prefix a2b index 30 permit 172.1.19.0 24

在DeviceA上配置发布策略,引用地址前缀列表a2b进行过滤。

DeviceA:
ospf 1
 filter-policy ip-prefix a2b export static

在DeviceB上查看IP路由表,可以看到DeviceB仅接收到列表a2b中定义的3条路由。

[~DeviceB]dis ip routing-table
Route Flags: R - relay, D - download to fib, T - to vpn-instance, B - black hole route
------------------------------------------------------------------------------
Routing Table : _public_
         Destinations : 16       Routes : 16        
Destination/Mask    Proto   Pre  Cost        Flags NextHop         Interface
      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
     172.1.17.0/24  O_ASE   150  1             D   192.158.1.1     Ethernet1/0/1
     172.1.18.0/24  O_ASE   150  1             D   192.158.1.1     Ethernet1/0/1
     172.1.19.0/24  O_ASE   150  1             D   192.158.1.1     Ethernet1/0/1
    192.158.1.0/24  Direct  0    0             D   192.158.1.2     Ethernet1/0/1
    192.158.1.2/32  Direct  0    0             D   127.0.0.1       Ethernet1/0/1
  192.158.1.255/32  Direct  0    0             D   127.0.0.1       Ethernet1/0/1
    192.158.2.0/24  Direct  0    0             D   192.158.2.1     Ethernet1/0/0
    192.158.2.1/32  Direct  0    0             D   127.0.0.1       Ethernet1/0/0
  192.158.2.255/32  Direct  0    0             D   127.0.0.1       Ethernet1/0/0
    192.158.3.0/24  Direct  0    0             D   192.158.3.1     Ethernet1/0/2
    192.158.3.1/32  Direct  0    0             D   127.0.0.1       Ethernet1/0/2
  192.158.3.255/32  Direct  0    0             D   127.0.0.1       Ethernet1/0/2
255.255.255.255/32  Direct  0    0             D   127.0.0.1       InLoopBack0
[~DeviceB]     
  1. 配置路由接收策略

在DeviceC上配置地址前缀列表in。

DeviceC:
ip ip-prefix in index 10 permit 172.1.18.0 24

在DeviceC上配置接收策略,引用地址前缀列表in进行过滤。

DeviceC:
ospf 1
 filter-policy ip-prefix in import

查看DeviceC的IP路由表,可以看到DeviceC的本地核心路由表中,仅接收了列表in定义的1条路由。

[~DeviceC-ospf-1]display ip routing-table 
Route Flags: R - relay, D - download to fib, T - to vpn-instance, B - black hole route
------------------------------------------------------------------------------
Routing Table : _public_
         Destinations : 8        Routes : 8         
Destination/Mask    Proto   Pre  Cost        Flags NextHop         Interface
      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
     172.1.18.0/24  O_ASE   150  1             D   192.158.2.1     Ethernet1/0/0
    192.158.2.0/24  Direct  0    0             D   192.158.2.2     Ethernet1/0/0
    192.158.2.2/32  Direct  0    0             D   127.0.0.1       Ethernet1/0/0
  192.158.2.255/32  Direct  0    0             D   127.0.0.1       Ethernet1/0/0
255.255.255.255/32  Direct  0    0             D   127.0.0.1       InLoopBack0
[~DeviceC-ospf-1]

查看DeviceC的OSPF路由表,可以看到OSPF路由表中接收到3条列表a2b中定义的路由。因为在链路状态协议中,filter-policy import命令用于过滤从协议路由表加入本地核心路由表的路由。

[~DeviceC-ospf-1]display ospf routing
          OSPF Process 1 with Router ID 192.158.2.2
                   Routing Tables
 Routing for ASEs
 Destination        Cost       Type       Tag        NextHop         AdvRouter      
 172.1.18.0/24      1          Type2      1          192.158.2.1     192.158.1.1    
 Total Nets: 1
 Intra Area: 0  Inter Area: 0  ASE: 1  NSSA: 0
          OSPF Process 65534 with Router ID 128.1.138.137
                   Routing Tables
 Routing for Network
 Destination        Cost     Type       NextHop         AdvRouter       Area           
 128.1.138.137/32   0        Direct     128.1.138.137   128.1.138.137   0.0.0.0        
 128.1.138.138/32   100      Stub       128.1.138.138   128.1.138.138   0.0.0.0        
 128.1.138.138/32   100      Stub       128.1.138.138   128.1.138.138   0.0.0.0        
 128.1.138.139/32   200      Stub       128.1.138.138   128.1.138.139   0.0.0.0        
 128.1.138.139/32   200      Stub       128.1.138.138   128.1.138.139   0.0.0.0        
 128.1.138.140/32   200      Stub       128.1.138.138   128.1.138.140   0.0.0.0        
 128.1.138.140/32   200      Stub       128.1.138.138   128.1.138.140   0.0.0.0        
                
 Total Nets: 4
 Intra Area: 4  Inter Area: 0  ASE: 0  NSSA: 0
[~DeviceC-ospf-1]

实际测试发现与华为手册不一致,filter-policy import不仅过滤本地核心路由表,也过滤了OSPF路由协议表,但没有过滤OSPF Database

[~DeviceC-ospf-1]dis ospf lsdb 
          OSPF Process 1 with Router ID 192.158.2.2
                  Link State Database
                          Area: 0.0.0.0
 Type      LinkState ID    AdvRouter        Age  Len   Sequence       Metric
 Router    192.158.1.1     192.158.1.1      808  36    80000003            1
 Router    192.158.1.2     192.158.1.2     1108  60    80000004            1
 Router    192.158.2.2     192.158.2.2     1117  36    80000002            1
 Router    192.158.3.2     192.158.3.2     1109  36    80000002            1
 Network   192.158.1.2     192.158.1.2     1132  32    80000001            0
 Network   192.158.2.2     192.158.2.2     1117  32    80000001            0
 Network   192.158.3.2     192.158.3.2     1109  32    80000001            0
                  AS External Database
 Type      LinkState ID    AdvRouter        Age  Len   Sequence       Metric
 External  172.1.17.0      192.158.1.1      803  36    80000001            1
 External  172.1.18.0      192.158.1.1      803  36    80000001            1
 External  172.1.19.0      192.158.1.1      803  36    80000001            1
          OSPF Process 65534 with Router ID 128.1.138.137
                  Link State Database
                          Area: 0.0.0.0
 Type      LinkState ID    AdvRouter        Age  Len   Sequence       Metric
 Router    128.1.138.137   128.1.138.137   1598  60    80000003          100
 Router    128.1.138.138   128.1.138.138   1599  96    80000006          100
 Router    128.1.138.139   128.1.138.139   1607  48    80000002          100
 Router    128.1.138.140   128.1.138.140   1608  60    80000003          100
                  Type 10 Opaque (Area-Local Scope) Database
 Type      LinkState ID    AdvRouter        Age  Len   Sequence   Area           
 Opq-Area  4.0.0.0         128.1.138.137   1264  32    80000002   0.0.0.0        
 Opq-Area  4.0.0.0         128.1.138.138   1318  32    80000002   0.0.0.0        
 Opq-Area  4.0.0.0         128.1.138.139   1247  32    80000002   0.0.0.0        
 Opq-Area  4.0.0.0         128.1.138.140   1339  32    80000002   0.0.0.0        
 Opq-Area  200.1.204.0     128.1.138.137   1665  84    80000001   0.0.0.0        
 Opq-Area  200.1.204.0     128.1.138.138   1665  84    80000001   0.0.0.0        
 Opq-Area  200.1.204.0     128.1.138.139   1663  84    80000001   0.0.0.0        
 Opq-Area  200.1.204.0     128.1.138.140   1666  84    80000001   0.0.0.0        
 Opq-Area  200.255.204.0   128.1.138.137   1604  36    80000002   0.0.0.0        
 Opq-Area  200.255.204.0   128.1.138.138   1598  36    80000004   0.0.0.0        
 Opq-Area  200.255.204.0   128.1.138.139   1599  36    80000003   0.0.0.0        
 Opq-Area  200.255.204.0   128.1.138.140   1599  36    80000003   0.0.0.0        
 Opq-Area  202.255.238.0   128.1.138.137   1665  68    80000001   0.0.0.0        
 Opq-Area  202.255.238.0   128.1.138.138   1665  68    80000001   0.0.0.0        
 Opq-Area  202.255.238.0   128.1.138.139   1663  68    80000001   0.0.0.0        
 Opq-Area  202.255.238.0   128.1.138.140   1666  68    80000001   0.0.0.0        
[~DeviceC-ospf-1]  

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值