华为网路设备学习-20 IGP路由专题-IP前缀列表

前一章讲了路由策略,其作用是作用于添加某条路由或者给某条路由添加优先级等设置。

存在某种情况下需要进行更精准的匹配某条路由,此时 ACL只能匹配一个路由的网络号,无法匹配网络掩码的短板就出现了。IP前缀列表(ip ip-prefix)则可以解决这一问题,其可以精准匹配网络号和掩码大小。

注意:ACL可以匹配 来源地 或 目的地,但IP前缀列表无法做到。

IP前缀列表(ip ip-prefix)

索引值可选

1.指定网络号长度16: 指需要匹配16位的网络号。

如: 192.168.***.***

网络号长度 是0则不需要考虑网络号

2.指定掩码长度的匹配范围: 指子网掩码的范围(掩码大小)

如:greater-equal 24 时,24≦掩码≦32

192.168.0.0/24 192.168.0.0/25 192.168.0.0/26 。。。。192.168.0.0/32

3.又如:

3.示例1:

注:网络号长度 是0则不需要考虑网络号

4、示例2

需要匹配网络位的最小值为 192.168.4.0 /22

但由于需要匹配的掩码为24,则需要指定掩码长度来匹配范围

此时若 192.168.8.0 /24 的路由来,由于网络位不匹配故丢弃

0 0 0 0 1 0 0 0

5、例3

用路由筛选替换掉ACL进行匹配

参考:华为网路设备学习-18 IGP路由专题-路由重发布(路由引入)

复制代码
[Huawei]sysname R1	
[R1]interface g0/0/0
[R1-GigabitEthernet0/0/0]ip address 192.168.12.1 24
[R1-GigabitEthernet0/0/0]q
 
[R1]rip	
[R1-rip-1]ver 2
[R1-rip-1]undo summary 
[R1-rip-1]network 192.168.12.0	
[R1-rip-1]q

[Huawei]sysname R2
[R2]interface g0/0/0
[R2-GigabitEthernet0/0/0]ip address 192.168.12.2 24
[R2-GigabitEthernet0/0/0]q
[R2]interface g0/0/1	
[R2-GigabitEthernet0/0/1]ip address 192.168.23.2 24
[R2-GigabitEthernet0/0/1]q
	
[R2]rip
[R2-rip-1]ver 2
[R2-rip-1]undo summary 
[R2-rip-1]network 192.168.12.0
 
[R2]ospf 1 router-id 2.2.2.2
[R2-ospf-1]area 0	
[R2-ospf-1-area-0.0.0.0]network 192.168.23.2 0.0.0.0

[Huawei]sysname R3	
[R3]int g0/0/1
[R3-GigabitEthernet0/0/1]ip address 192.168.23.3 24
[R3-GigabitEthernet0/0/1]q
 
[R3]ospf 1 router-id 3.3.3.3
[R3-ospf-1]area 0
[R3-ospf-1-area-0.0.0.0]network 192.168.23.3 0.0.0.0

添加测试路由

R1\]ip route-static 192.168.0.0 24 NULL 0 \[R1\]ip route-static 192.168.0.0 16 NULL 0 将该路由引入rip 和ospf \[R1\]rip \[R1-rip-1\]import-route static \[R2\]ospf \[R2-ospf-1\]import-route rip ![](https://i-blog.csdnimg.cn/direct/26e15bb3da154adfbe116660a57054a6.png) 此时要求在R3上过滤掉 明细路由192.168.0.0 24 如果使用acl进行,会将192.168.0.0 24 和 192.168.0.0 16 两条路由都屏蔽掉 ACL只能匹配一个路由的网络号,无法匹配网络掩码 [R2]acl 2000 [R2-acl-basic-2000]rule deny source 192.168.0.0 0 [R2-acl-basic-2000]rule permit [R2-acl-basic-2000]q [R2]route-policy test permit node 10 Info: New Sequence of this List. [R2-route-policy]if-match acl 2000 [R2-route-policy]q [R2]ospf 1 [R2-ospf-1]import-route rip route-policy test ![](https://i-blog.csdnimg.cn/direct/6f6c9090846c477eb26a2b2d109d1994.png) 如果使用IP前缀列表(ip ip-prefix) [R2]ip ip-prefix haha deny 192.168.0.0 24 [R2]ip ip-prefix haha permit 0.0.0.0 0 less-equal 32 [R2]route-policy test2 permit node 10 [R2-route-policy]if-match ip-prefix haha [R2]ospf 1 [R2-ospf-1]display this [V200R003C00] # ospf 1 router-id 2.2.2.2 import-route rip 1 route-policy test area 0.0.0.0 network 192.168.23.2 0.0.0.0 # return [R2-ospf-1]undo import-route rip [R2-ospf-1]import-route rip route-policy test2 ![](https://i-blog.csdnimg.cn/direct/848e3b9cdd8445cdaf3eb37c360512d5.png)

相关推荐
落羽凉笙2 小时前
Python学习笔记(3)|数据类型、变量与运算符:夯实基础,从入门到避坑(附图解+代码)
笔记·python·学习
Quintus五等升2 小时前
深度学习①|线性回归的实现
人工智能·python·深度学习·学习·机器学习·回归·线性回归
小二·2 小时前
前端监控体系完全指南:从错误捕获到用户行为分析(Vue 3 + Sentry + Web Vitals)
前端·vue.js·sentry
Web极客码2 小时前
如何在Ubuntu服务器上安装和配置BIND9
服务器·数据库·ubuntu
吳所畏惧3 小时前
Linux环境/麒麟V10SP3下离线安装Redis、修改默认密码并设置Redis开机自启动
linux·运维·服务器·redis·中间件·架构·ssh
jz_ddk3 小时前
[学习] 卫星导航的码相位与载波相位计算
学习·算法·gps·gnss·北斗
阿珊和她的猫3 小时前
`require` 与 `import` 的区别剖析
前端·webpack
西***63474 小时前
全兼容・高安全:KVM 一站式服务器远程监控与管理指南
服务器
谎言西西里4 小时前
零基础 Coze + 前端 Vue3 边玩边开发:宠物冰球运动员生成器
前端·coze
努力的小郑4 小时前
2025年度总结:当我在 Cursor 里敲下 Tab 的那一刻,我知道时代变了
前端·后端·ai编程